Syntaxerror: invalid syntax (python and pycharm)

Asked

Viewed 27 times

-1

I don’t know why you made a mistake in pycharm, how can I fix it?

I used the following libraries

import pandas as pd
import yfinance as yf
import datetime
import lxml
from kora.selenium import wd
from time import sleep

def busca_carteira_teorica(indice, espera=8):
    url = f'https://sistemaswebb3-listados.b3.com.br/indexPage/day/{indice.upper()}?language=pt-br'
    wd.get(url)
    sleep(espera)

    wd.find_element_by_id('segment').send_keys("Setor de Atuação")
    sleep(espera)

    wd.find_element_by_link_text("Download").click()
    sleep(espera)

    arquivos = !ls - 1t *.csv
    return pd.read_csv(arquivos[0], sep=';', encoding='ISO-8859-1', skipfooter=2, engine='python', thousands='.', decimal=',', header=1, index_col=False)

I’d like to replace the mistake arquivos = !ls - 1t *.csv with a code that the file downloaded in csv goes to the directory where the code file is running or in the cloud (I don’t know if I was clear). That’s all you’re making a mistake here

inserir a descrição da imagem aqui

  • What should make this sentence arquivos = !ls - 1t *.csv ???? Behold subprocess.Popen()

  • I am layman in python and I am trying to transfer from googlecolab to pycharm I took this video https://youtu.be/b9bU_ryC5rc?t=582 it seems that I need to put the directory of my PC, but I do not know how to do this, can help me please

  • 1

    This syntax is not typical of python, this operator ! is a Jupyter Notebook operator, which in turn is the Google Colab engine, used to make shell command line calls. In Python you can execute a shell command with subprocess.Popen(). Ex: import the module subprocess and replace the line that generates the error with arquivos = subprocess.Popen(['ls', '-lt', '*.csv'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) see the documentation for a more suitable use in your case.

  • worked out, thanks!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.