See it to believe it


#1



https://www.codecademy.com/courses/python-intermediate-en-OGNHh/0/1?curriculum_id=4f89dab3d788890003000096


Hey Guys,
I was wondering how to create a file from python instead of transfering from one file to another. It is hard for me to convey, but I am trying to create a file , what am i doing wrong?


my_list = [i**2 for i in range(1,11)]
# Generates a list of squares of the numbers 1 - 10

f = open("output.txt", "w")

for item in my_list:
    f.write(str(item) + "\n")

f.close()


#2

my_list = [i**2 for i in range(1,11)]
# Generates a list of squares of the numbers 1 - 10

f = open("output.txt", "w")

for item in my_list:
    f.write(str(item) + "\n")

f.close()

This code worked for me.


#3

the code works fine but im trying to create a file on my computer for this code, is that possible?


#4

I'm not sure I follow you. Are you saying that you want to run this as a Python script on your local computer?


#5

yes, but it isnt working quite right


#6

Error Message:
SyntaxError: multiple statements found while compiling a single statement


#7

This runs correctly for me from a local file. I just copy/pasted the code into a plain text file, and ran it with python file.py. I'm using a Mac.
There could be spacing issues if you copy/pasted it.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.