geekcomputers / Python

My Python Examples
http://www.thegeekblog.co.uk
MIT License
31.59k stars 12.25k forks source link

testlines.py code not working #731

Open Xelany57 opened 4 years ago

Xelany57 commented 4 years ago

Hello,

this is probabaly the simplest of all codes in the zip file but I cant make it work

It should create a test.txt file in the same directory but it doesnt do anything for me Plus i dont understand why there is a "s = " before the write statement Sorry Im new to python and github, I just finished the crash course python from no starch press

BR,

tanishqvyas commented 4 years ago

@Xelany57 Hey, I'll be happy to help you on this. What python version are you using? The code seems to work perfectly well for me. Could you elaborate a bit more about the issue you are facing.

The s= isn't mandatory, it just holds the number of characters we wrote in the file.

Xelany57 commented 4 years ago

I think I have the latest version of Python (3.7.4)

Well I assumed that when running the file using the python interpreter it should create a text file named "test.txt" with written inside "I am beven"

For me when I take it just does nothing when I run it using python, I place it in another folder to make sure im not missing the output file, but really it doesn't do anything, I see the window appearing very quickly and closing just as quickly, no file is created

Do you have any clue? How does it work for you?

Thanks!

Xelany57 commented 4 years ago

@Xelany57 Hey, I'll be happy to help you on this. What python version are you using? The code seems to work perfectly well for me. Could you elaborate a bit more about the issue you are facing.

The s= isn't mandatory, it just holds the number of characters we wrote in the file.

@tanishqvyas See my previous answer please : )

tanishqvyas commented 4 years ago

@Xelany57 Isn't Pythone interpreter used to interpret code rather than executing files ? I suggest you run the file using some IDE or on terminal using the command For Windows

python filename.py

For Linux

python3 filename.py
tanishqvyas commented 4 years ago

@Xelany57 I ran the file by placing it in a folder named Downloads. Then I changed my present working directory to Downloads. After that I opened my terminal and typed

python3 filename.py

The code ran just the way you expected

Xelany57 commented 4 years ago

@tanishqvyas Thanks for the help as I suspected it was very simple

I ran it using "python file" command and it output the file as expected, I played with the program a bit and it works as intended

I assume you are on linux because when I run "python3 file" command it doesn't work, but when I remove the 3 it works

I thought the interpreter was able to run the code, I was wrong on that

A bit off topic, but do you know some good ressources/ways to improve in Python? I already did the crash course python from no starch press, even if i didnt complete all the projects yet

I think Ill need to improve the most in django or other web frameworks, it is for my job...

If you do have ideas Ill happily take them if not I already thank you for your help! Thanks!

tanishqvyas commented 4 years ago

@Xelany57 I am glad to help you. Yes, I am on linux. I mostly learn from online resources. Since you specifically mentioned Django. For basics you can refer to these

  1. Freecodecamp's youtube channel has a Django Crash course.
  2. Django Girls is a really nice website to learn Django.
  3. One of the best and official resources is obviously the documentation itself.

I could suggest you a bit more depending upon how much have you learnt from starch press. Sorry but I haven't taken a look at their course, so won't be able to suggest according to that.

Recently I made a very basic django project. You can have a look at it. Welcome again.

atharvakadlag commented 4 years ago

@tanishqvyas I checked your django projects it would be better if you would add dependancies in readme.

kapil8279 commented 4 years ago

Don't worry I'll do it for you