[Solved] python code gives different results on my machine

Need help with C, C++, perl, python, etc?

[Solved] python code gives different results on my machine

Postby adido » 2018-06-11 11:22

hi,

I'm learning Python and when I compile one of the exercises from the course, the results come strikingly different than the original version. This is not me solving an exercise! It is an example that I ran from file & interpreter, and the results I receive are different (similar on my machine, but different than other machines).

I posted on the Python forum, but there's no solution yet https://python-forum.io/Thread-py4e-boo ... n-compiled

I was thinking maybe there is a package issue...

Any ideas?
Thanks!
Last edited by adido on 2018-06-13 11:46, edited 1 time in total.
adido
 
Posts: 15
Joined: 2014-02-10 11:57

Re: python code gives different results on my machine

Postby Dai_trying » 2018-06-11 12:53

I just tested in my Jessie machine and got this output
Code: Select all
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> data = 'From stephen.marquard@uct.ac.za Sat Jan  5 09:14:16 2008'
>>> atpos = data.find('@')
>>> print (atpos)
21
>>> spos = data.find(' ',atpos)
>>> print (spos)
31
>>> host = data[atpos+1 : spos]
>>> print (host)
uct.ac.za


I also tested in my Buster installation and get the same (correct) results just with newer Python and GCC versions, which leads me to think there could be a problem with your python installation (just a guess really).
Dai_trying
 
Posts: 447
Joined: 2016-01-07 12:25

Re: python code gives different results on my machine

Postby reinob » 2018-06-12 17:07

My bet is that the space (' ') is not a real space but something you've copied over from HTML (&nbsp or who knows what).
Type the program yourself, with a normal (ASCII) editor.
reinob
 
Posts: 541
Joined: 2014-06-30 11:42

Re: python code gives different results on my machine

Postby sunrat » 2018-06-13 00:19

+1 for what reinob said. I had the same problem recently.
See viewtopic.php?f=8&t=137518&p=675102#p675102
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!
User avatar
sunrat
 
Posts: 2323
Joined: 2006-08-29 09:12
Location: Melbourne, Australia

[Solved] python code gives different results on my machine

Postby adido » 2018-06-13 11:46

reinob wrote:My bet is that the space (' ') is not a real space but something you've copied over from HTML (&nbsp or who knows what).
Type the program yourself, with a normal (ASCII) editor.


son of a...
Thank you, there was a problem with space in the string I believe... I first edited the (' ') and had the same results. Then I re-did all the spaces in the string and it all worked!
Many thanks!
adido
 
Posts: 15
Joined: 2014-02-10 11:57


Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable