Python SyntaxError: EOL while scanning string literal: Open and close command - python-3.x

I tried to program and it always gave error. Where's the problem?
I didn't understand how it works.
I already put the command open and close read .txt
import time
print ("Oi Y")
time.sleep (2)
import time
print ("Sou Crash e fui criado pelo pai CrashX")
time.sleep (2)
import time
print ("O pai me pediu que eu leio para você")
time.sleep (2)
import time
print ("Aguarde")
time.sleep (5)
import time
f = open("C:\P.txt", 'r')
file_data = f.read()
print (file_data)
time.sleep (10)
file_data2 = f.close()
print (file_data2)
import time
print ("Encerrando...")
time.sleep (5)
import time
print ("Obrigado!)
time.sleep (5)

Related

My python program does not write the accents in the Spanish language

this is my code
import pyautogui
import time
f = open('spambot\spam.txt', 'r')
time.sleep(5)
for words in f:
print(words)
pyautogui.typewrite(words)
pyautogui.press("enter")
time.sleep(3)
the content of spam.txt is this
"Yo sé que no me te importó"
but this is what it prints
"Yo s que no te import"
You can edit this line adding an encoding that is appropriate for Spanish: 'utf', 'utf-8' or 'utf-8-sig' work fine:
f = open('spam.txt', 'r', encoding='utf-8-sig')

The python program with datetime mofule

I write this code in python in order to read the minute of windows clock and recognize weather it is even or odd and do it 10 times with random sleep time between 5 to 10 seconds:
from datetime import datetime
import random
import time
wait_time = random.randint(5,11)
time.sleep(wait_time)
for i in range(10):
even=[2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,
34,36,38,40,42,44,46,48,50,52,54,56,58]
m=datetime.today().minute
if m in even:
print("It is even")
else:
print("It is odd")
But when I run it, sleep time works ok but it show the answer just one time. I think I should write the lines in other arrangement. But I don't know how to fix it.
You need to rearrange your lines according to your own description as below. Same lines but another ordering.
from datetime import datetime
import random
import time
even=[2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,
34,36,38,40,42,44,46,48,50,52,54,56,58]
for i in range(10):
m=datetime.today().minute
if m in even:
print("It is even")
else:
print("It is odd")
wait_time = random.randint(5,11)
time.sleep(wait_time)

Stock price logging function

I have this function where the price of a stock gets logged in real time every 2 seconds and save it into a csv file however I cant see anything in the csv when I open it. What am I missing from the script?
import pandas as pd
import time
import urllib
import sys
import fix_yahoo_finance as yf
def stocks():
# Enter stock symbol
stock = input("Enter stock: ")
# Name CSV file
csvy= str(stock) + time.strftime('.%A.%d.%b.%Y').replace(' ', '') + ".csv"
csvy = csvy.replace(':' , '')
with open(csvy, 'w') as f:
sys.stdout = f
while 1 > 0:
print(yf.get_live_price(stock))
time.sleep(2)
stocks()
You wrote:
print(yf.get_live_price(stock))
You want to additionally flush the buffer so your new text is immediately visible:
print(yf.get_live_price(stock), flush=True)
Alternatively, consider assigning the live price to a temp variable,
and then outputting it twice, with print() and f.write(),
rather than assigning a new value to stdout.
Then you'd be able to flush them independently according to your need,
f.flush() or sys.stdout.flush().

Command line prints should be saved in .txt file every 10min with multiple trail's

Import os
Import time
While True:
Os.system("speed test.exe")
Time.sleep(1000)
Try this
import os
import time
index = 0
while True:
os.system(f"speed test.exe > speed_text_{index}.txt")
index+=1
time.sleep(1000)

Restarting every few minutes

I have the following code:
from alpha_vantage.timeseries import TimeSeries
import matplotlib.pyplot as plt
import sys
def stockchart(symbol):
ts = TimeSeries(key='1ORS1XLM1YK1GK9Y', output_format='pandas')
data, meta_data = ts.get_intraday(symbol=symbol, interval='1min', outputsize='full')
print (data)
I wanted to know how can i 'keep alive' so to say so that there a new request every say 5 mins for data? Is while loop the most efficient way to do this?
You mean like:
import time
while True:
ts = TimeSeries(key='1ORS1XLM1YK1GK9Y', output_format='pandas')
data, meta_data = ts.get_intraday(symbol=symbol, interval='1min', outputsize='full')
print (data)
time.sleep(300)
To achieve infinite recursion: Python "while" loops
And to wait for 5 minutes: time.sleep
Hope that answers your question!

Resources