Re: [Tutor] HELP-Regarding python

2013-01-30 Thread bob gailer

On 1/30/2013 1:51 AM, Gayathri S wrote:

I am sorry that you chose to ignore my request to start a new email with 
a relevant subject.


Please next time do so.

The easier you make it for us to help you the more likely we will want 
to help.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] changing unicode to ascii

2013-01-30 Thread Benjamin Fishbein
>  Using text.encode("ascii", "ignore") should absolutely work. You could also 
> just write the file in UTF-8 if you don't absolutely need ascii by using 
> text.encode("utf-8").
> 
> Hugo
You're right. It does work. I forgot to assign the result to a variable:
text = text.encode("ascii", "ignore")
Thanks.

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


Re: [Tutor] changing unicode to ascii

2013-01-30 Thread Peter Otten
Benjamin Fishbein wrote:

> I was trying to write text to a file and got the following error:
> 
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in
> position 5495: ordinal not in range(128)
> 
> I tried several things I found online, such as:
> text.encode("ascii", "ignore")
> which gave me the same error

Try saving text with

assert type(text) == unicode
with open(filename, "w") as f:
   f.write(text.encode("ascii", "ignore"))

If that fails please give the exact traceback. Don't paraphrase, use cut-
and-paste!

If the above works you can preserve your precious data including non-ascii 
characters with

import io

assert type(text) == unicode
with io.open(filename, "w") as f:
f.write(text)

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


Re: [Tutor] changing unicode to ascii

2013-01-30 Thread Hugo Arts
On Wed, Jan 30, 2013 at 2:39 PM, Benjamin Fishbein wrote:

> I was trying to write text to a file and got the following error:
>
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in
> position 5495: ordinal not in range(128)
>
> I tried several things I found online, such as:
>
> text.encode("ascii", "ignore")
>
> which gave me the same error
>
> and
> text.replace("\xa0", "")
>
> again, UnicodeEncodeError
>
> I tried
> text.decode("ascii", "ignore")
> and got the same result.
>
> I'm using Python 2.7, so there's some special technique for this version?
> I think the utf-8 data is unnecessary; I can strip it if I can't convert
> it to ascii.
> Of course, I can't figure out how to strip it either.
> Any help is much appreciated.
> Thanks,
> Ben
>
>
Please show us the relevant parts of your code so we can properly diagnose
the issue. Using text.encode("ascii", "ignore") should absolutely work. You
could also just write the file in UTF-8 if you don't absolutely need ascii
by using text.encode("utf-8").

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


[Tutor] changing unicode to ascii

2013-01-30 Thread Benjamin Fishbein
I was trying to write text to a file and got the following error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 
5495: ordinal not in range(128)

I tried several things I found online, such as:
text.encode("ascii", "ignore")
which gave me the same error

and
text.replace("\xa0", "")

again, UnicodeEncodeError

I tried
text.decode("ascii", "ignore")
and got the same result.

I'm using Python 2.7, so there's some special technique for this version?
I think the utf-8 data is unnecessary; I can strip it if I can't convert it to 
ascii.
Of course, I can't figure out how to strip it either.
Any help is much appreciated.
Thanks,
Ben

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


Re: [Tutor] automate add-to-cart with python

2013-01-30 Thread Walter Prins
Hi,


Now I just have to figure out how to write the code with the selenium
> module.
>
>
Install the Firefox extension/add-on "Selenium IDE" which will help with
that too:

http://seleniumhq.org/download/

http://seleniumhq.org/docs/02_selenium_ide.jsp#

It's effectively a browser macro recorder which can emit the action
recording in multiple languages, including 2 flavours of Python (depending
on how you're using Selenium.)

You can copy/paste the actions directly from the recorder or export them as
Python.  Set the clipboard format as "Python" under the
"Options"->"Clipboard format" menu, then select some recorded commands
(click, shift-click as per usual and then ctrl-c to copy and ctrl-v to
paste, or to export them click "File"->"Export test-case as" and pick one
of the Python options.

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


Re: [Tutor] automate add-to-cart with python

2013-01-30 Thread Benjamin Fishbein

On Jan 29, 2013, at 11:49 PM, Marc Tompkins wrote:
> 
> I'm pretty sure that's a typo.  It should say:
> python virtualenv.py
> 
Woohoo!!! It works.
You're right. It worked this way and I was able to install pip.
And I got selenium to work.
Apparently the problem is that selenium isn't compatible with Python 2.5, so I 
installed 2.7 and when I typed "import selenium," it worked! 
Now I just have to figure out how to write the code with the selenium module.
Thanks for your help, everyone.
Ben

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


[Tutor] Fwd: HELP-Regarding python

2013-01-30 Thread Walter Prins
Gayathri,


On 30 January 2013 06:51, Gayathri S  wrote:

> Hi All!
>  I don't know how to read text file in python. If the data
> values are stored in a text file format, for example(1,30,60,90,120...200)
> means what i would do for reading it in python. could you just explain it.
>
>
>
>   Thanks!
>
>
The answers you've been given so far assume vanilla Python and no add-on
packages.  However your previous similar questions regarding this was
apparently in the context of some sort of machine learning or data analysis
context, and was using scikit or some other addon package (pandas?) for
Python.   So  I suspect your question really is (supposing you're using the
Python "Pandas" package),  "how do I read a text file into a Pandas
dataframe?"  Can you please clarify what you're really asking and whether
the above question is still in the context of some other package?

You must understand that Python is a general purpose programming language,
and therefore that the idioms and ways of expressing certain things (like
reading a text file "into" Python) in the base language will be different
from how one would do it if you're using a specific specialized package.

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