[Tutor] File reading-(encoding problems)

2015-12-23 Thread Ratheesh kumar
Here is my code..try:
data=open('info.txt')
for each_line in data:
try:
(role,line_spoken)=each_line.split(':',1)
print(role,end='')
print(' said: ',end='')
print(line_spoken,end='')
except ValueError:
print(each_line)
data.close()
except IOError:
 print("File is missing")The actual output is 
Man said:  Is this the right room for an argument?
Other Man said:  I've told you once.
Man said:  No you haven't!
Other Man said:  Yes I have.The characters  ""  got added to the contents of 
my file in the beginning. Later identified it as a encoding problem. I cleared 
the problem by adding the encoding arguments when opening the file( 
data=open('info.txt',encoding='utf-8-sig')).Now my question is each time do I 
have to make this change or is there away to make this encoding a default one?  
 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] File reading-(encoding problems)

2015-12-23 Thread Ben Finney
Ratheesh kumar  writes:

> Here is my code..try:
> data=open('info.txt')

[…]

Please be sure to present the code as distinct lines.

You have posted it as plain text (good), the indentation is preserved
(good). The problem here is that your commentary is mingled with the
program code, so that it's difficult to see where the program begins and
ends.

> Man said:  No you haven't!
> Other Man said:  Yes I have.The characters  ""  got added to the
> contents of my file in the beginning.

And again here, you've somehow got your commentary stuck directly onto
the output example. Please be sure to use one empty line to surround any
code examples or output examples.

> Later identified it as a encoding problem. I cleared the problem by
> adding the encoding arguments when opening the file(
> data=open('info.txt',encoding='utf-8-sig')).Now my question is each
> time do I have to make this change or is there away to make this
> encoding a default one?

Yes, you need to specify the encoding of text, when you input or output
that text as bytes (e.g. in a file). Representing text as bytes is done
with a text encoding, and you must be explicit about that encoding
because guessing the encoding leads to heartache.

Your use of an explicit encoding in that program is correct.

-- 
 \“I took it easy today. I just pretty much layed around in my |
  `\underwear all day. … Got kicked out of quite a few places, |
_o__)  though.” —Bug-Eyed Earl, _Red Meat_ |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Using python 3 on Ubuntu 14.04

2015-12-23 Thread Jim Byrnes
I am in the process of moving from unbutu 12.04 to 14.04. I was doing 
some testing and got this:


jfb@Jims-1404:~$ cd MyProgs
jfb@Jims-1404:~/MyProgs$ cd passwords
jfb@Jims-1404:~/MyProgs/passwords$ python3 passwords.py
Traceback (most recent call last):
  File "passwords.py", line 8, in 
from PythonCard import  model,clipboard
ImportError: No module named 'PythonCard'

If I simply start it with  python passwords.py  it runs fine. There is 
no need to use python 3 on this particular program but if I wanted to 
write for python 3 in the future what do I need to do to run programs 
with it?


Thanks,  Jim

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using python 3 on Ubuntu 14.04

2015-12-23 Thread Ben Finney
Jim Byrnes  writes:

> If I simply start it with  python passwords.py  it runs fine.

If you type ‘python --version’ and ‘python3 --version’ you will see two
different version numbers.

Different versions of Python have their own separate run-time
environments. Any modules you want a particular Python interpreter to
import, must be installed specifically for that interperter to find.

> There is no need to use python 3 on this particular program but if I
> wanted to write for python 3 in the future what do I need to do to run
> programs with it?

You need to install the Python 3 modules for the correct Python 3
version.

-- 
 \“It is undesirable to believe a proposition when there is no |
  `\   ground whatever for supposing it true.” —Bertrand Russell, _The |
_o__)   Value of Scepticism_, 1928 |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using python 3 on Ubuntu 14.04

2015-12-23 Thread Alex Kleider

On 2015-12-23 14:58, Jim Byrnes wrote:

I am in the process of moving from unbutu 12.04 to 14.04. I was doing
some testing and got this:

jfb@Jims-1404:~$ cd MyProgs
jfb@Jims-1404:~/MyProgs$ cd passwords
jfb@Jims-1404:~/MyProgs/passwords$ python3 passwords.py
Traceback (most recent call last):
  File "passwords.py", line 8, in 
from PythonCard import  model,clipboard
ImportError: No module named 'PythonCard'

If I simply start it with  python passwords.py  it runs fine. There is
no need to use python 3 on this particular program but if I wanted to
write for python 3 in the future what do I need to do to run programs
with it?

Thanks,  Jim


Jim, make

#!/usr/bin/env python3

the very first line in your myscript.py file
and change it's permissions with the following command:

chmod 775 myscript.py

Then you'll be able to run it simply by entering

./password.py

on the command line.

PS I don't think this will fix your current problem which is
probably the result of importing something that exists with
Python 2 but not 3- specifically PythonCard.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using python 3 on Ubuntu 14.04

2015-12-23 Thread Mark Lawrence

On 23/12/2015 22:58, Jim Byrnes wrote:

I am in the process of moving from unbutu 12.04 to 14.04. I was doing
some testing and got this:

jfb@Jims-1404:~$ cd MyProgs
jfb@Jims-1404:~/MyProgs$ cd passwords
jfb@Jims-1404:~/MyProgs/passwords$ python3 passwords.py
Traceback (most recent call last):
   File "passwords.py", line 8, in 
 from PythonCard import  model,clipboard
ImportError: No module named 'PythonCard'

If I simply start it with  python passwords.py  it runs fine. There is
no need to use python 3 on this particular program but if I wanted to
write for python 3 in the future what do I need to do to run programs
with it?

Thanks,  Jim



Read this https://docs.python.org/3/howto/pyporting.html.

Find a replacement for anything that relies on PythonCard as it hasn't 
been supported for years.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using python 3 on Ubuntu 14.04

2015-12-23 Thread Nnamdi Anyanwu
If you're installing modules with pip, install pip3 and install the
appropriate modules using pip3 instead of using regular pip.
On Dec 24, 2015 12:12 AM, "Alex Kleider"  wrote:

> On 2015-12-23 14:58, Jim Byrnes wrote:
>
>> I am in the process of moving from unbutu 12.04 to 14.04. I was doing
>> some testing and got this:
>>
>> jfb@Jims-1404:~$ cd MyProgs
>> jfb@Jims-1404:~/MyProgs$ cd passwords
>> jfb@Jims-1404:~/MyProgs/passwords$ python3 passwords.py
>> Traceback (most recent call last):
>>   File "passwords.py", line 8, in 
>> from PythonCard import  model,clipboard
>> ImportError: No module named 'PythonCard'
>>
>> If I simply start it with  python passwords.py  it runs fine. There is
>> no need to use python 3 on this particular program but if I wanted to
>> write for python 3 in the future what do I need to do to run programs
>> with it?
>>
>> Thanks,  Jim
>>
>
> Jim, make
>
> #!/usr/bin/env python3
>
> the very first line in your myscript.py file
> and change it's permissions with the following command:
>
> chmod 775 myscript.py
>
> Then you'll be able to run it simply by entering
>
> ./password.py
>
> on the command line.
>
> PS I don't think this will fix your current problem which is
> probably the result of importing something that exists with
> Python 2 but not 3- specifically PythonCard.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using python 3 on Ubuntu 14.04

2015-12-23 Thread Alan Gauld
On 24/12/15 00:00, Mark Lawrence wrote:

> Find a replacement for anything that relies on PythonCard as it hasn't 
> been supported for years.

"Years" might be a bit much, there was an update for most
distros 10 months ago, so its not quite dead. But since it
relies on wxPython and that doesn't yet support Python 3
the result is the same. If you need it to work on python3
don't use PythonCard

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using python 3 on Ubuntu 14.04

2015-12-23 Thread Alan Gauld
On 23/12/15 23:15, Nnamdi Anyanwu wrote:
> If you're installing modules with pip, install pip3 and install the
> appropriate modules using pip3 instead of using regular pip.

Most v3 modules are also available via the Ubuntu package system
so you can install via synaptic which I tend to find more reliable
than pip.

YMMV,

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor