Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Help me for my exams !

Bidoule

New Coder
Hi everyone, I hope y'all doing great.

I'm a brand new coder here. I need to learn how to code in python. I'll keep this thread active while my progression though the year and your help.

First of all, I need to convert a .csv into a .py ... I tried to look up on the internet but I found nothing. Could you guys help me out ?
Thanks a lot !!
Have a nice day
 
A .csv is just basically a graph the closest thing I would think of is .json or python:
Python:
Name = "John Smith"
Address = "1600 Pennsylvania Ave NW, Washington, DC 20500"
JSON:
[ "Person": {
   "Name": "John Smith",
    "Address": "1600 Pennsylvania Ave NW, Washington, DC 20500"
}]
Or if you want arrays:
JSON:
    {"employees":[ 
        {"name":"Shyam", "email":"[email protected]"}, 
        {"name":"Bob", "email":"[email protected]"}, 
        {"name":"Jai", "email":"[email protected]"} 
    ]}
 
Last edited by a moderator:
To explain the problem the subject is "create a GPS with Python"
So I have a doc with all cities in France (I'm french) and I need to link them together.
So for example, I'm in Paris and the closest city is "Idon'tknow" and it's at 900km away from Marseille.
I don't need to do the path just the distances ...
 
Hi everyone, I hope y'all doing great.

I'm a brand new coder here. I need to learn how to code in python. I'll keep this thread active while my progression though the year and your help.

First of all, I need to convert a .csv into a .py ... I tried to look up on the internet but I found nothing. Could you guys help me out ?
Thanks a lot !!
Have a nice day
To put it simply... what you are asking is to convert a file used to store data, similar to exel, and convert it to a file that contains code, like python file (.py)... not doable.. however, if your goal is to read and/or the data contained within the .csv file with a program written in python, then yes, that is doable :)

What is it that you need to do with the data in the CSV file? Let's start with that :)
 
To put it simply... what you are asking is to convert a file used to store data, similar to exel, and convert it to a file that contains code, like python file (.py)... not doable.. however, if your goal is to read and/or the data contained within the .csv file with a program written in python, then yes, that is doable :)

What is it that you need to do with the data in the CSV file? Let's start with that :)
What I need to do is, I have a file with data and I have to work with these data using python.
I asked to someone about my problem, he said I must open it as a .txt so I can read the data, get all the data into a list and then work with that list.
I don't know if I'm understandable, put I'll put down what I've done as soon as I can !
 
What I need to do is, I have a file with data and I have to work with these data using python.
I asked to someone about my problem, he said I must open it as a .txt so I can read the data, get all the data into a list and then work with that list.
I don't know if I'm understandable, put I'll put down what I've done as soon as I can !
You don't necessarily need to open it up as a text file. You should be able to just open it as a csv in Python.
 
Python:
import csv
csv_file = raw_input('Enter the name of your input file: ')
txt_file = raw_input('Enter the name of your output file: ')
with open(txt_file, "w") as my_output_file:
    with open(csv_file, "r") as my_input_file:
        [ my_output_file.write(" ".join(row)+'\n') for row in csv.reader(my_input_file)]
    my_output_file.close()
You can look more on this, https://stackoverflow.com/questions...t-csv-file-to-text-file-using-python#47340240
 
Python:
import csv
csv_file = raw_input('Enter the name of your input file: ')
txt_file = raw_input('Enter the name of your output file: ')
with open(txt_file, "w") as my_output_file:
    with open(csv_file, "r") as my_input_file:
        [ my_output_file.write(" ".join(row)+'\n') for row in csv.reader(my_input_file)]
    my_output_file.close()
You can look more on this, https://stackoverflow.com/questions...t-csv-file-to-text-file-using-python#47340240
To add to sago's response, you can also look here

 

Latest posts

Buy us a coffee!

Back
Top Bottom