Output not showing on Jupiter Lab for Python - python

After print command output is not showing. It happens few time back, after an hour same code runs smoothly. As I am a beginner I don't know much about what's happening.
first = 'dip'
last = 'rakshit'
print = (first, last)

Just remove the "="
first='dip'
last='rakshit'
print(first,last)

Related

ValueError: Value of 'x' is not the name of a column in 'data_frame'

I need help with my code, at first it run and showed results but second time of running it crashed and showed me an error, I tried everything to fix it but nothing. any help? would appreciate it.
figure = px.scatter(data_frame = data,
x="distance",
y="Time_taken(min)",
size="Time_taken(min)",
trendline="ols",
title = "Relationship Between Distance and Time Taken")
figure.show()
I tried everything to fix it, but nothing worked

Why does print("..."), i.e. three dots in a row, print blank?

I'd like to print three dots in a row (to form an ellipsis), but print() prints blank.
print("one moment...")
one moment...
print("...")
print("..")
..
print("...abc...")
abc...
print("\u2026")
…
What's happening here? Why is "..." parsed in an exceptional way?
I am using ipython in PyCharm.
Looks like this is a known issue with Pycharm where its interactive console removes the leading three periods from a print statement. Here’s the ticket tracking this issue.
A possible workaround for now is defining something like:
def iprint(obj):
if (s:=str(obj)).startswith("..."):
print(" "+s)
else:
print(s)
which looks like:
>>> iprint("...ymmv")
...ymmv

How to use the most recently printed line as an input?

I am trying to create a Twitter bot that posts a random line from a text file. I have gone as far as generating the random lines, which print one at a time, and giving the bot access to my Twitter app, but I can't for the life of me figure out how to use a printed line as a status.
I am using Tweepy. My understanding is that I need to use api.update_status(status=X), but I don't know what X needs to be for the status to match the most recently printed line.
This is the relevant section of what I have so far:
from random import choice
x = 1
while True:
file = open('quotes.txt')
content = file.read()
lines = content.splitlines()
print(choice(lines))
api.update_status(status=(choice(lines)))
time.sleep(3600)
The bot is accessing Twitter no problem. It is currently posting another random quote generated by (choice(lines)), but I'd like it to match what prints immediately before.
I may not fully understand your question, but from the very top, where it says, "How to use the most recently printed line as an input", I think I can answer that. Whenever you use the print() command, store the argument into a string variable that overwrites its last value. Then it saves the last printed value.
Instead of directly printing a choice:
print(choice(lines))
create a new variable and use it in your print() and your api.update_status():
selected_quote = choice(lines)
print(selected_quote)
api.update_status(status=selected_quote)

Program doesn't append file using variables, but no error message appears

Using Python 3.4.2
I'm working on a quiz system using python. Though it hasn't been efficient, it has been working till now.
Currently, I have a certain user log in, take a quiz, and the results of the quiz get saved to a file for that users results. I tried adding in so that it also saves to a file specific to the subject being tested, but that's where the problem appears.
user_score = str(user_score)
user_score_percentage_str = str(user_score_percentage)
q = open('user '+(username)+' results.txt','a')
q.write(test_choice)
q.write('\n')
q.write(user_score+'/5')
q.write('\n')
q.write(user_score_percentage_str)
q.write('\n')
q.write(user_grade)
q.write('\n')
q.close()
fgh = open(test_choice+'results.txt' ,'a')
fgh.write(username)
fgh.write('\n')
fgh.write(user_score_percentage_str)
fgh.write('\n')
fgh.close
print("Your result is: ", user_score , "which is ", user_score_percentage,"%")
print("Meaning your grade is: ", user_grade)
Start()
Everything for q works (this saves to the results of the user)
However, once it comes to the fgh, the thing doesn't work at all. I receive no error message, however when I go the file, nothing ever appears.
The variables used in the fgh section:
test_choice this should work, since it worked for the q section
username, this should also work since it worked for the q section
user_score_percentage_str and this, once more, should work since it worked for the q section.
I receive no errors, and the code itself doesn't break as it then correctly goes on to print out the last lines and return to Start().
What I would have expected in the file is to be something like:
TestUsername123
80
But instead, the file in question remains blank, leading me to believe there must be something I'm missing regarding working the file.
(Note, I know this code is unefficient, but except this one part it all worked.)
Also, apologies if there's problem with my question layout, it's my first time asking a question.
And as MooingRawr kindly pointed out, it was indeed me being blind.
I forgot the () after the fgh.close.
Problem solved.

Getting input constantly using python multithreading

I want to write a program which will print a string every second on the other hand it will allow user to write text, I have the code snippet below. My problem is everytime a new line is printed, input line is also disturbed. Is there a way to seperate the output lines from the input line?
import time
from thread import start_new_thread
def heron():
while 1:
time.sleep(1)
print "some text"
start_new_thread(heron,())
c = raw_input("Enter text>")
I doubt you can do this without curses. There might be another way, but I don't think it would be very pretty. There's a basic how-to here.

Categories

Resources