Re: how to detect comment in source code file ?

2013-09-04 Thread Ben Finney
[email protected] writes:

> how works python interpreter for finding comment ?

It works as specified in the language reference. In particular, see
http://docs.python.org/3/reference/lexical_analysis.html#comments>.

> if possible find nested comment ?

Python's comments are line-end comments only. The syntax does not allow
multi-line nor nested comments.

-- 
 \   “If you go flying back through time and you see somebody else |
  `\   flying forward into the future, it's probably best to avoid eye |
_o__)   contact.” —Jack Handey |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Beginner's guide to Python

2013-09-04 Thread Chris Angelico
On Wed, Sep 4, 2013 at 3:26 PM, Steve Hayes  wrote:
> Can anyone recommend a web site that gives a good beginner's guide to Python?
>
> One that tells one, especially --
>
> -- what kind of projects Python is good for
> -- what kind of projects it is not good for
> -- a simple explanation of how it works
> -- a kind of beginner's tutotial and guide to its syntax
>
> I've read about Python, and installed it on my computer when I found it on a
> DVD that came with a magazine, but I haven't got a clue about how to use it.
>
> So any advice on the best web sites for absolute novices would be welcome.

I'd start with the standard docs tutorial:

http://docs.python.org/3/tutorial/

Which version of Python have you installed? You may want to consider,
if the DVD has an old version, getting the latest one off the web
site.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Beginner's guide to Python

2013-09-04 Thread prashanth B.G
Hi Steve ,

   These links might be of help .

   http://swaroopch.com/notes/python/   -- Very well explained for
beginners

   http://www.diveintopython.net/  -- Must read to pick up advanced
stuff . This can also be used as a starting point to figure out what python
might be used for .


  Hope this works for you .

Thanks.


On Wed, Sep 4, 2013 at 10:56 AM, Steve Hayes  wrote:

> Can anyone recommend a web site that gives a good beginner's guide to
> Python?
>
> One that tells one, especially --
>
> -- what kind of projects Python is good for
> -- what kind of projects it is not good for
> -- a simple explanation of how it works
> -- a kind of beginner's tutotial and guide to its syntax
>
> I've read about Python, and installed it on my computer when I found it on
> a
> DVD that came with a magazine, but I haven't got a clue about how to use
> it.
>
> So any advice on the best web sites for absolute novices would be welcome.
>
>
> --
> Steve Hayes from Tshwane, South Africa
> Blog: http://khanya.wordpress.com
> E-mail - see web page, or parse: shayes at dunelm full stop org full stop
> uk
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
 *HAVE A NICE DAY *

 Prashanth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: to be pythonic: should caller or callee log?

2013-09-04 Thread Gildor Oronar

El 04/09/13 10:26, Ethan Furman escribió:


I would say it is not really the caller's or the callee's job to do the
logging, even though it should be done.  What would be really handy is a
function that sat in between the caller and callee that logged for you
-- you know, a decorator:


Thanks a lot! My knowledge to decorator is so limited to @staticmethod 
that I don't know I can write my own decorator. This is a good lesson to 
learn.


Your example lead me to explore and find this article which addressed 
the case of using decorator to log:


http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/
(To googler who find this post: search 'log' in the above article)
--
https://mail.python.org/mailman/listinfo/python-list


Re: to be pythonic: should caller or callee log?

2013-09-04 Thread Gildor Oronar

Thanks:

El 04/09/13 05:01, Terry Reedy escribió:


I would expect that every account class has a transaction method.
* If so, just call it, but
assertIsNot(DebitAccount.transaction, AbstractAccount.transaction)
for every subclass in your test suite.
* If not, perhaps you need an abstract subclass TransAccount. Then use
hasattr in production code and the isnot test in test code.


I would assume that you categorize this as a unit test problem, because 
you consider an Acount not implementing Transaction is a bug, right?


There are two occassions an account is intended not having Transaction 
function, both not test-related:


1. The acount doesn't offer this feature. e.g. Certificate of Deposit. 
This can be in TransAccount.


2. The 3rd-party account offer this feature but doesn't qualify the 
software's requirement, e.g. not returning the result in 3 seconds, and 
is avoided when planning the deal (I am writing an auto-trade software). 
This case you cannot categorize those who can into TransAccount, 
beacause 1) that naming imply other accounts don't do transaction but 
they do, just not good enough; 2) when other accounts becomes good 
enough, the change (to inheritance) is a bit too invasive.

--
https://mail.python.org/mailman/listinfo/python-list


Re: can't find win32api from embedded pyrun call

2013-09-04 Thread Tim Golden
On 03/09/2013 21:50, David M. Cotter wrote:
> I find i'm having this problem, but the solution you found isn't
> quite specific enough for me to be able to follow it.
> 
> I'm embedding Python27 in my app.  I have users install
> ActivePython27 in order to take advantage of python in my app, so the
> python installation can't be touched as it's on a user's machine.
> 
> When I attempt to do:
>> import win32api
> 
> i get this:
>> Traceback (most recent call last): File "startup.py", line 5, in
>>  ImportError: DLL load failed: The specified module could
>> not be found.

You'll likely get more input from the guys on the python-win32 list.

Most times I've come across this issue it's been because the pywin32
package (or the whole Python distribution if you're using ActiveState)
was not installed as an administrator / elevated. I'm not sure I've ever
fathomed why, and the investigation isn't helped by the import dance
which the pywin32 code does. I don't remember solving it without a
reinstall on the user's machine.

TJG
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how does not work nested comment in python?

2013-09-04 Thread Vlastimil Brom
2013/9/4  :
> example:
>
> print "hello" # print comment +"world"=> single line comment
> print "hello" '''print comment''' +"world"   => multiple line comment
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
python only has single line comments, which apply from a "#" to the
end of the respective line.
There are some possibilities/workarounds/hacks for "commenting out",
i.e. (temporarily) disabling, parts of the code
if False:


Sometimes triple-quoted multiline strings are (mis)used this way
""

which actually converts the code to a not accessible multiline string.
However, triple quoting is not an official means for multiline comments.
What you are seeing in your second example is implicit string
concatenation (which works regardless of the type of the quotes) -
adjacent string literals in the code are joined automatically:
>>> "abc" 'def' """ghi""" '''jkl'''
'abcdefghijkl'
>>>

hth,
  vbr
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Antoon Pardon
Op 03-09-13 17:23, [email protected] schreef:

> 
> 
> The Latin alphabet uses Greek lettering.
> 
> The Cyrillic alphabet uses Greek lettering.
> 
> Greek: One should not confuse modern Greek
> with ancient Greek, polytonic Greek full
> of diacritics.
> 
> Plenty of European languages (~15) based on the Latin
> alphabet uses some ancient Greek diacritics.
> 
> Now unicode.
> 
> Everything is working very smoothly with the endorsed coding
> schemes of Unicode.org.
> 
> Expectedly it fails (behaves badly) with Python and its 
> Flexible Sting Representation, mainly because it relies on
> the latin-1 (iso-8859-1) set.

You really seem obsessed. There is no reason at all to think that is
problem is related to the FSR. You are only bringing this up, because
you are looking for opportunities to complain about the FSR.

> To take the problem the other way, one can take these
> linguistic ascpects to illustrate the wrong design of
> the FSR.

No you can't, you are just assuming so because you feel it would
confirm your bias against the FSR.

-- 
Antoon Pardon
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to detect comment in source code file ?

2013-09-04 Thread Paul Rudin
Ben Finney  writes:

> [email protected] writes:
>
>> how works python interpreter for finding comment ?
>
> It works as specified in the language reference. In particular, see
> http://docs.python.org/3/reference/lexical_analysis.html#comments>.
>
>> if possible find nested comment ?
>
> Python's comments are line-end comments only. The syntax does not allow
> multi-line nor nested comments.

Although you can use unbound multi-line strings as a kind of
comment. But its often better to make the strings into doc strings
proper.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Ferrous Cranus
Τη Δευτέρα, 2 Σεπτεμβρίου 2013 9:28:36 μ.μ. UTC+3, ο χρήστης Dave Angel έγραψε:
> On 2/9/2013 11:05, Ferrous Cranus wrote:
> 
> 
> 
> > Στις 2/9/2013 3:21 μμ, ο/η Dave Angel έγραψε:
> 
> >> Starting with the byte string in the error message:
> 
> > f = open("junk.txt", "w")
> 
> > f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
> > \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')
> 
> > f.close()
> 
> >
> 
> >
> 
> > Ιndeed but yet again, file checks out the encoding of the filename that 
> 
> > consists of these lines above, not of the actual strings.
> 
> >
> 
> >
> 
> 
> 
> 'file' does nothing interesting with the filename, it just opens it and
> 
> examines the contents.  For example,
> 
> 
> 
> file www/cgi-bin/files.py
> 
> 
> 
> will examine the Python source file, not run it.
> 
> 
> 
> So first in the interpreter, I ran
> 
> 
> 
>  f = open("junk.txt", "w")
> 
>  f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
>  \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')
> 
>  f.close()
> 
> 
> 
> then at the bash prompt, I ran:
> 
> 
> 
> davea@think2:~$ file junk.txt 
> 
> junk.txt: ISO-8859 text


That is one Clever Idea Dave.

I take it that the charset of the file 'junk.txt' gets identified by the 
characters encoding that read form within the file?

But wait a minute: What editor do you uses to write these 3 lines?
I mean am a bit confused.

i for example i 'nano tets.py' which has within:

f = open("junk.txt", "w") 
f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
\xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') 
f.close() 

then when i save the file within nano for example by default in utf-8 charset

how would it be able to detect the bytestring within that is supposed to be of 
greek-iso's
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: eGenix pyOpenSSL Distribution 0.13.2.1.0.1.5

2013-09-04 Thread eGenix Team: M.-A. Lemburg

ANNOUNCING

   eGenix.com pyOpenSSL Distribution

 Version 0.13.2.1.0.1.5


 An easy-to-install and easy-to-use distribution
 of the pyOpenSSL Python interface for OpenSSL -
available for Windows, Mac OS X and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.2.1.0.1.5.html


INTRODUCTION

The eGenix.com pyOpenSSL Distribution includes everything you need to
get started with SSL in Python.

It comes with an easy-to-use installer that includes the most recent
OpenSSL library versions in pre-compiled form, making your application
independent of OS provided OpenSSL libraries:

http://www.egenix.com/products/python/pyOpenSSL/

pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS-
aware network applications as well as certificate management tools:

https://launchpad.net/pyopenssl/

OpenSSL is an open-source implementation of the SSL/TLS protocol:

http://www.openssl.org/


NEWS

This new release of the eGenix.com pyOpenSSL Distribution includes a
set of updates related to security problems reported by Christian
Heimes:

New in the eGenix pyOpenSSL Distribution


* Added a patch by Christian Heimes to pyOpenSSL: This addresses the
  CVE-2013-4238 related problem with embedded NUL bytes in
  subjectAltNames and also fixes a memory leak in the X509
  .get_extension() method.

* Christian Heimes also pointed us to a problem with the included CA
  root bundle, which turns out to be rather wide-spread. Mozilla's
  certificate bundle includes more than just the trusted CA root
  certificates. It also includes several explicitly untrusted root
  certificates and even single untrusted server certificates.

  Our investigation showed that while OpenSSL does handle trust
  parameters in the certificates, it doesn't use this information
  during certificate verification, if the certificate is passed in
  together with other trusted certificates. Future OpenSSL versions
  may add this support, but at least versions up to and including
  1.0.1e don't have it.

  To work around this problem, we have split the bundle file into
  separate bundles, each with different trust settings included. The
  explicitly untrusted certificates are no longer included in the
  lists to avoid potentially trusting these untrusted (root)
  certificates.

  Many thanks to Christian Heimes for these reports.

* Added new TRUST_* constants to the OpenSSL.ca_bundle module and new
  purpose parameters to various bundle query functions.

* Fixed a missing import in the https_client.py example.

As always, we provide binaries that include both pyOpenSSL and the
necessary OpenSSL libraries for all supported platforms:
Windows x86 and x64, Linux x86 and x64, Mac OS X PPC, x86 and x64.

We've also added egg-file distribution versions of our eGenix.com
pyOpenSSL Distribution for Windows, Linux and Mac OS X to the
available download options. These make setups using e.g. zc.buildout
and other egg-file based installers a lot easier.


DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/pyOpenSSL/


UPGRADING

Before installing this version of pyOpenSSL, please make sure that
you uninstall any previously installed pyOpenSSL version. Otherwise,
you could end up not using the included OpenSSL libs.

___
SUPPORT

Commercial support for these packages is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.


MORE INFORMATION

For more information about the eGenix pyOpenSSL Distribution, licensing
and download instructions, please visit our web-site or write to
[email protected].

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Sep 04 2013)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...   http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


: Try our mxODBC.Connect Python Database Interface for free ! ::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Ma

Re: MySQL data types vs Django/Python data types

2013-09-04 Thread Fábio Santos
On 1 Sep 2013 21:54, "Gary Roach"  wrote:
>
> Hi all,
>
> System:
> Debian Wheezy Linux
> Python 2.7
> Django 1.5
> MySql 5.5
>
> I am new to Python and Django and am having trouble matching Python data
types with those of MySQL. MySQL has about 7 basic data types including
Blobs, Binaries, etc. It also has a rich selection of geometry types. In
addition, types like INT have 7 or 8 different options like Primary Key,
zero fill, auto inc, etc. I can't seem to find anything in python to match
these. I am trying to build a model.py for an existing database that was
created with MySQL Workbench.

First, I want to state that you need to understand that Django was designed
to help build simple, common use case web apps. Database skins, as someone
put it. The ORM is very easy to use, although it is not well prepared for
some things.

It also has a very nice advantage, which is being compatible with many
RDBMS so you can have postgresql on the production server and sqlite on
your development machine. This ends up being bad too. For instance, if it
is not possible to do something in a specific rdbms, for instance, let's
say blobs, Django will not be able to implement it because it has to
support those several rdbms.

There are many hacks ( http://djangosnippets.org/snippets/1597/ ) but hacks
will be hacks and you want your app to be reliable and not compromise your
code quality right from the start, right?

Many field options have equivalents in Django (primary key, auto
increment). You just have to find them. For auto increment there is
AutoField. Primary key is an option of the base Field (so you can provide
it as a keyword argument to any field).

Also if you want gis geometry data types (is that what you meant?) you can
install and use geodjango.

> I do not wish to use anything other than MySQL because of the complexity
of my storage needs (searchable text, PDF, Audio, Video and Photos). The
text searches will often be word phrase searches through thousands of
documents. I need the speed and the data type flexibility.

Are you sure mysql is up to it? For searchable text you will want to have
an index, and while mysql's FULLTEXT kind of works, it is clearly not a
core feature. Some options for it are enabled or disabled in compile time.
Also, I won't judge but it's often wrong to use a rdbms to store
PDF/audio/video. Those belong in the file system or nosql storage.

> How do I build or modify a model.py to do this. I really don't want to
write a model.py manually. That would really be a major pain. Workbench to
the database an import to Django and edit is my choice. Unfortunately, the
model.py produced has lost most of the functionality of the original
database and I can't seem to figure out how to fix it.
>
> Any help will be sincerely appreciated.
>
> Gary R.

A lot can be done by using the database manually. Django helps you a bit
here, for instance it gives you access to the database cursor for raw SQL
access to the database, supports custom fields, and every orm query "chain"
(like MyModel.objects.all().filter(...)) can be incremented with raw SQL
"where" and "select" clauses.

But you might not want to be using Django or at least not its ORM.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Ferrous Cranus
Τη Τετάρτη, 4 Σεπτεμβρίου 2013 5:14:31 π.μ. UTC+3, ο χρήστης Piet van Oostrum 
έγραψε:

> Where does it display that?
> Do you happen to read that mail in a Microsoft program?

yes. Thunderbird.
 
> If yes, then it is the fault of that program. Read the mail in some
> other program and you will probably see that the proper From address is
> there.

i used retrieval of 'nikosatsuperhost.gr' within GMail's service.

Same way of dispalyment there too.


> The problem is that Gmail inserts a "Sender" header with your account
> (email address) and certain Microsoft programs use that to display as
> the From address instead of the real From address. 

I think it's logical to act that way.

The real 'FROM' address that GMail uses to send mail from my 'mail.py' to some 
recipient is my real GMail's account address, and not the FROM address that any 
arbitrary poster posts in a html webform hwich can be totally fake,  i.e. 
[email protected]

I believe any kind of mail client will be have this way.
We need some way to dicth the Sender FROM string or alter it to the one uses in 
the webform.
-- 
https://mail.python.org/mailman/listinfo/python-list


Downloading the feed using feedparser

2013-09-04 Thread mukesh tiwari
Hello all,
I am trying to download the feed of http://blogs.forrester.com/feed but I am 
stuck with a problem. 

>>> import feedparser
>>> d = feedparser.parse('http://blogs.forrester.com/feed')
>>> d.etag
u'"1378291653-1"'
>>> d.modified
'Wed, 04 Sep 2013 10:47:33 +'

>>> feedparser.parse('http://blogs.forrester.com/feed', etag=d.etag, 
>>> modified=d.modified).status
200

When I am running this, should not this be 304 ( The content can't be change so 
fast in a moment or this server is not configured properly ). If I rely on this 
then whenever I run the code, I will download the content irrespective of 
content changed or not. Could some one please suggest me how to avoid the 
duplicate download ? 

The below one is working fine so if I try to download again then I will get 304 
response since no data is changed on server.

>>> d = feedparser.parse("feed://feeds.huffingtonpost.com/HP/MostPopular")
>>> d.etag
u'Vx5oxwMUzEFvFpd6BNR23912Zk4'
>>> d.modified
'Wed, 04 Sep 2013 10:32:06 GMT'
>>> feedparser.parse("feed://feeds.huffingtonpost.com/HP/MostPopular", etag= 
>>> d.etag, modified=d.modified).status
304

Thank you
Mukesh Tiwari
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Dave Angel
On 4/9/2013 05:57, Ferrous Cranus wrote:

> Τη Τετάρτη, 4 Σεπτεμβρίου 2013 5:14:31 π.μ. UTC+3, ο χρήστης Piet van Oostrum 
> έγραψε:
>
>> Where does it display that?
>> Do you happen to read that mail in a Microsoft program?
>
> yes. Thunderbird.

When did Microsoft take over Thunderbird's development

In any case, Thunderbird has te ability to display the actual message
received.  See menu:
   View->MessageSource


>  
>> If yes, then it is the fault of that program. Read the mail in some
>> other program and you will probably see that the proper From address is
>> there.
>
> i used retrieval of 'nikosatsuperhost.gr' within GMail's service.
>
> Same way of dispalyment there too.
>
>
>> The problem is that Gmail inserts a "Sender" header with your account
>> (email address) and certain Microsoft programs use that to display as
>> the From address instead of the real From address. 
>
> I think it's logical to act that way.
>
> The real 'FROM' address that GMail uses to send mail from my 'mail.py' to 
> some recipient is my real GMail's account address, and not the FROM address 
> that any arbitrary poster posts in a html webform hwich can be totally fake,  
> i.e. [email protected]
>
> I believe any kind of mail client will be have this way.
> We need some way to dicth the Sender FROM string or alter it to the one uses 
> in the webform.

-- 
DaveA


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Dave Angel
On 4/9/2013 04:35, Ferrous Cranus wrote:

> Τη Δευτέρα, 2 Σεπτεμβρίου 2013 9:28:36 μ.μ. UTC+3, ο χρήστης Dave Angel 
> έγραψε:
>> On 2/9/2013 11:05, Ferrous Cranus wrote:
>> 
>> 
>> 
>> > Στις 2/9/2013 3:21 μμ, ο/η Dave Angel έγραψε:
>> 
>> >> Starting with the byte string in the error message:
>> 
>> > f = open("junk.txt", "w")
>> 
>> > f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
>> > \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')
>> 
>> > f.close()
>> 
>> >
>> 
>> >
>> 
>> > Ιndeed but yet again, file checks out the encoding of the filename that 
>> 
>> > consists of these lines above, not of the actual strings.
>> 
>> >
>> 
>> >
>> 
>> 
>> 
>> 'file' does nothing interesting with the filename, it just opens it and
>> 
>> examines the contents.  For example,
>> 
>> 
>> 
>> file www/cgi-bin/files.py
>> 
>> 
>> 
>> will examine the Python source file, not run it.
>> 
>> 
>> 
>> So first in the interpreter, I ran
>> 
>> 
>> 
>>  f = open("junk.txt", "w")
>> 
>>  f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
>>  \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')
>> 
>>  f.close()
>> 
>> 
>> 
>> then at the bash prompt, I ran:
>> 
>> 
>> 
>> davea@think2:~$ file junk.txt 
>> 
>> junk.txt: ISO-8859 text
>
>
> That is one Clever Idea Dave.
>
> I take it that the charset of the file 'junk.txt' gets identified by the 
> characters encoding that read form within the file?

'file' only guesses the most likely encoding for 'junk.txt'  But at
least it can know it's not utf-8, since that would give an decoding
error.

That's why, whenever 'file' makes its verdict, it's up to you to check
it by displaying the data after decoding it with that tentative
encoding.

>
> But wait a minute: What editor do you uses to write these 3 lines?
> I mean am a bit confused.

As I said right above, "in the interpreter, I ran"...
And if that's not clear enough, you can see the  prompts that the
Python interpreter uses.  By interpeter, I mean I ran Python with no
parameters.  I did not run IDLE or any other IDE, that might take it
upon itself to interfere.


>
> i for example i 'nano tets.py' which has within:
>
> f = open("junk.txt", "w") 
> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
> \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') 
> f.close() 
>
> then when i save the file within nano for example by default in utf-8 charset

That's the encoding for the file tets.py, and you'll notice that it's
actually ASCII.  Notice that the string I copied from the error message
uses escape sequences for all non-ASCII bytes.

>
> how would it be able to detect the bytestring within that is supposed to be 
> of greek-iso's

I wouldn't be running 'file' on the tets.py file, but on the junk.txt
file created when you run
python tets.py

So since the tets.py file was a sidetrack, I just ran those three lines
in the interpreter.

-- 
DaveA


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Ferrous Cranus

Στις 4/9/2013 2:15 μμ, ο/η Dave Angel έγραψε:

Τη Τετάρτη, 4 Σεπτεμβρίου 2013 5:14:31 π.μ. UTC+3, ο χρήστης Piet van Oostrum 
έγραψε:

Where does it display that?
Do you happen to read that mail in a Microsoft program?

yes. Thunderbird.

When did Microsoft take over Thunderbird's development

In any case, Thunderbird has te ability to display the actual message
received.  See menu:
View->MessageSource



I meant i'm using ThunderBird and not Outlook Express.

I doesn't matter what the mail headers say but the actual presentation 
of the email which state always that it was sent by my personal GMail 
address and not from the mail address that was posted int he webform


--
Webhost 
--
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Ferrous Cranus

Στις 4/9/2013 2:26 μμ, ο/η Dave Angel έγραψε:

On 4/9/2013 04:35, Ferrous Cranus wrote:


Τη Δευτέρα, 2 Σεπτεμβρίου 2013 9:28:36 μ.μ. UTC+3, ο χρήστης Dave Angel έγραψε:

On 2/9/2013 11:05, Ferrous Cranus wrote:




Στις 2/9/2013 3:21 μμ, ο/η Dave Angel έγραψε:



Starting with the byte string in the error message:



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



f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
\xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')



f.close()











Ιndeed but yet again, file checks out the encoding of the filename that



consists of these lines above, not of the actual strings.












'file' does nothing interesting with the filename, it just opens it and

examines the contents.  For example,



file www/cgi-bin/files.py



will examine the Python source file, not run it.



So first in the interpreter, I ran




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



f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
\xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')



f.close()




then at the bash prompt, I ran:



davea@think2:~$ file junk.txt

junk.txt: ISO-8859 text



That is one Clever Idea Dave.

I take it that the charset of the file 'junk.txt' gets identified by the 
characters encoding that read form within the file?


'file' only guesses the most likely encoding for 'junk.txt'  But at
least it can know it's not utf-8, since that would give an decoding
error.

That's why, whenever 'file' makes its verdict, it's up to you to check
it by displaying the data after decoding it with that tentative
encoding.



But wait a minute: What editor do you uses to write these 3 lines?
I mean am a bit confused.


As I said right above, "in the interpreter, I ran"...
And if that's not clear enough, you can see the  prompts that the
Python interpreter uses.  By interpeter, I mean I ran Python with no
parameters.  I did not run IDLE or any other IDE, that might take it
upon itself to interfere.




i for example i 'nano tets.py' which has within:

f = open("junk.txt", "w")
f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
\xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')
f.close()

then when i save the file within nano for example by default in utf-8 charset


That's the encoding for the file tets.py, and you'll notice that it's
actually ASCII.  Notice that the string I copied from the error message
uses escape sequences for all non-ASCII bytes.



how would it be able to detect the bytestring within that is supposed to be of 
greek-iso's


I wouldn't be running 'file' on the tets.py file, but on the junk.txt
file created when you run
 python tets.py

So since the tets.py file was a sidetrack, I just ran those three lines
in the interpreter.


I'm still consused about this.

say we save those 3 lines inside junk.txt and we save it by default as utf-8

when we 'file junk.txt'

what will file respond with?

filename's charset?

or

will it llook at the bystering within to decide what encoding it uses?

fi

--
Webhost 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python TUI that will work on DOS/Windows and Unix/Linux

2013-09-04 Thread James Harris
"James Harris"  wrote in message 
news:[email protected]...
> Am looking for a TUI (textual user interface) mechanism to allow a Python 
> program to create and update a display in text mode. For example, if a 
> command prompt was sized 80x25 it would be made up of 80 x 25 = 2000 
> characters. The Python program would need to be able to write to any of 
> those 2000 characters at any time though in practice the display would 
> normally be arranged by dividing it up into non-overlapping rectangular 
> regions.
>
> I have seen that there are various libraries: urwid, newt, console, dialog 
> etc. But they seem to be either for Unix or for DOS, not for both. I am 
> looking for a library that will run under either.

In case anyone else is following this, people have emailed me directly 
suggesting ncurses, pdcurses and these:

Pygcurse (http://inventwithpython.com/pygcurse/)
UniCurses (http://sourceforge.net/projects/pyunicurses/)

Naturally, all of these are centred on curses. I have been reading up on it 
and must say that the whole curses approach seems rather antiquated. I 
appreciate the suggestions and they may be what I need to do but from what I 
have seen of curses it was designed principally to provide common ways to 
control cursor-based terminals. That was a-la-mode in the days when we had 
terminals with different cursor control strings and I remember programming 
VT100 and VT52 monitors or terminals like them. But now it seems cumbersome.

I haven't thought too much about it so this is not a design proposal but it 
might be better to divide a display up into non-overlapping windows and 
treat each one separately. Writes to one would not be able to affect the 
others. A given window could allow writes to fixed locations or could behave 
as a glass teletype, writing to the bottom of the window and scrolling as 
needed, or could behave as a viewing port into a data structure. Something 
like that may be more useful to a programmer even if it has to use curses 
underneath because that's all that the OS provides.

James


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how does not work nested comment in python?

2013-09-04 Thread Dave Angel
On 4/9/2013 02:13, [email protected] wrote:

> example: 
>  
> print "hello" # print comment +"world"=> single line comment

>>> print "hello" # print comment +"world"=> single line comment
hello


> print "hello" '''print comment''' +"world"   => multiple line comment

>>> print "hello" '''print comment''' +"world"   => multiple line comment
  File "", line 1
print "hello" '''print comment''' +"world"   => multiple line comment
 ^
SyntaxError: invalid syntax
>>> print "hello" '''print comment''' +"world"
helloprint commentworld

What is your question?  The first line has a comment on it, the second
one does not.

-- 
DaveA


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: to be pythonic: should caller or callee log?

2013-09-04 Thread Xaxa Urtiz
Le mercredi 4 septembre 2013 09:44:27 UTC+2, Gildor Oronar a écrit :
> Thanks:
> 
> 
> 
> El 04/09/13 05:01, Terry Reedy escribió:
> 
> 
> 
> > I would expect that every account class has a transaction method.
> 
> > * If so, just call it, but
> 
> > assertIsNot(DebitAccount.transaction, AbstractAccount.transaction)
> 
> > for every subclass in your test suite.
> 
> > * If not, perhaps you need an abstract subclass TransAccount. Then use
> 
> > hasattr in production code and the isnot test in test code.
> 
> 
> 
> I would assume that you categorize this as a unit test problem, because 
> 
> you consider an Acount not implementing Transaction is a bug, right?
> 
> 
> 
> There are two occassions an account is intended not having Transaction 
> 
> function, both not test-related:
> 
> 
> 
> 1. The acount doesn't offer this feature. e.g. Certificate of Deposit. 
> 
> This can be in TransAccount.
> 
> 
> 
> 2. The 3rd-party account offer this feature but doesn't qualify the 
> 
> software's requirement, e.g. not returning the result in 3 seconds, and 
> 
> is avoided when planning the deal (I am writing an auto-trade software). 
> 
> This case you cannot categorize those who can into TransAccount, 
> 
> beacause 1) that naming imply other accounts don't do transaction but 
> 
> they do, just not good enough; 2) when other accounts becomes good 
> 
> enough, the change (to inheritance) is a bit too invasive.

Hello,
and what about something like that :


class AbsctractAccount():
 def transaction(self, amount, target):
 logging.info("Start transaction of %s to %s" % (amount, target))
 self.DoTransaction(amount,target)

 def DoTransaction(self,amount,target):
 pass # or raise notimplemented or do not implement this methods in the 
abstract class
 ...

class DebitAccount(AbstractAccount):
 def DoTransaction(self, amount, target):
 ...

class SomeOtherAccount(...)
  
like that you only have to write the logging function once.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Dave Angel
On 4/9/2013 07:29, Ferrous Cranus wrote:

> Στις 4/9/2013 2:15 μμ, ο/η Dave Angel έγραψε:
>>> Τη Τετάρτη, 4 Σεπτεμβρίου 2013 5:14:31 π.μ. UTC+3, ο χρήστης Piet van 
>>> Oostrum έγραψε:
 Where does it display that?
 Do you happen to read that mail in a Microsoft program?
>>> yes. Thunderbird.
>> When did Microsoft take over Thunderbird's development
>>
>> In any case, Thunderbird has te ability to display the actual message
>> received.  See menu:
>> View->MessageSource
>>
>
> I meant i'm using ThunderBird and not Outlook Express.
>
> I doesn't matter what the mail headers say but the actual presentation 
> of the email which state always that it was sent by my personal GMail 
> address and not from the mail address that was posted int he webform
>

One way to distinguish a bug in the python logic and in gmail, from a
bug in the mail reader is to examine the message source.  Others may be
able to guess what it looks like, but I cannot.

-- 
DaveA


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Heiko Wundram
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 03.09.2013 09:48, schrieb Ferrous Cranus:
> Si there a workaround for that please?

Yes, use/setup your own mailserver. Google will not allow you to send
as ("i.e., From:") an arbitrary address besides the one you've
authenticated as.

- -- 
- --- Heiko.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.20 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSJyUuAAoJEDMqpHf921/SksoIAJyFyYDN9zj/SypXERj+W1wK
fRuby0EyfWWMQayJ7SlbiSUzK3OF1ZVxO5s3WqGdXWI2WhXrrZbltuMyHedlBcqy
Dl9F1MtpItg01weICAYJCNcTNm649PCAuc47zbGahE7tDeJwU9xNlgEgXfnpx+eX
RvtyYAJlYnz5MTfftYZS9AxxEbaA+k5TNHcVE+5m3YX3Uno6rW+T19H4z4wC374K
MHxN4jS+z/qaZ+fDIkK6Uq8aRC5PA9pI37iTD5dJFikKugcp/9AqssnsEUkhMAGV
dcGPJnI1tiGrSLY6Q8q31DpkAlO79ETA4ag0yGvnjtmR/ZZjENlb2Ikls7JOA9Y=
=JDjl
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Dave Angel
On 4/9/2013 07:38, Ferrous Cranus wrote:

> Στις 4/9/2013 2:26 μμ, ο/η Dave Angel έγραψε:

>>

 So first in the interpreter, I ran



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

 f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')

 f.close()



 
>> So since the tets.py file was a sidetrack, I just ran those three lines
>> in the interpreter.
>>
> I'm still consused about this.
>
> say we save those 3 lines inside junk.txt and we save it by default as utf-8
>
> when we 'file junk.txt'
>
> what will file respond with?

junk2.txt: ASCII text

>
> filename's charset?
>
> or
>
> will it llook at the bystering within to decide what encoding it uses?
>

'file' isn't magic.  And again, it doesn't look at the filename, it
looks at the content.  What heuristics it uses, I don't know, but it has
hundreds of them.   ( I wish you hadn't confused the issue by using the
same name junk.txt for an entirely different purpose) When it looks at a
file like this one, it looks only at the bytes within it. In this
case, the instance of 'file' on my machine decides it's an ASCII file.

if I add an silly shebang line

#!/usr/tmp/pyttthon

it says
junk2.txt: a /usr/tmp/pyttthon script, ASCII text executable

It doesn't know it's python, it just trusts the shebang line.  And it
identifies it as ASCII, not utf-8, since there are no non-ascii
characters in it.  It certainly does not try to interpret the b''
byte string by Python syntax rules.




-- 
DaveA


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread wxjmfauth
Le mercredi 4 septembre 2013 10:01:50 UTC+2, Antoon Pardon a écrit :
> Op 03-09-13 17:23, [email protected] schreef:
> 
> 
> 
> > 
> 
> > 
> 
> > The Latin alphabet uses Greek lettering.
> 
> > 
> 
> > The Cyrillic alphabet uses Greek lettering.
> 
> > 
> 
> > Greek: One should not confuse modern Greek
> 
> > with ancient Greek, polytonic Greek full
> 
> > of diacritics.
> 
> > 
> 
> > Plenty of European languages (~15) based on the Latin
> 
> > alphabet uses some ancient Greek diacritics.
> 
> > 
> 
> > Now unicode.
> 
> > 
> 
> > Everything is working very smoothly with the endorsed coding
> 
> > schemes of Unicode.org.
> 
> > 
> 
> > Expectedly it fails (behaves badly) with Python and its 
> 
> > Flexible Sting Representation, mainly because it relies on
> 
> > the latin-1 (iso-8859-1) set.
> 
> 
> 
> You really seem obsessed. There is no reason at all to think that is
> 
> problem is related to the FSR. You are only bringing this up, because
> 
> you are looking for opportunities to complain about the FSR.
> 
> 
> 
> > To take the problem the other way, one can take these
> 
> > linguistic ascpects to illustrate the wrong design of
> 
> > the FSR.
> 
> 
> 
> No you can't, you are just assuming so because you feel it would
> 
> confirm your bias against the FSR.
> 
> 
> 
> -- 
> 
> Antoon Pardon




jmf
-- 
https://mail.python.org/mailman/listinfo/python-list


Dealing with \r in CSV fields in Python2.4

2013-09-04 Thread Tim Chase
I've got some old 2.4 code (requires an external lib that hasn't been
upgraded) that needs to process a CSV file where some of the values
contain \r characters.  It appears that in more recent versions (just
tested in 2.7; docs suggest this was changed in 2.5), Python does the
Right Thing™ and just creates values in the row containing that \r.
However, in 2.4, the csv module chokes on it with

  _csv.Error: newline inside string

as demoed by the example code at the bottom of this email.  What's the
best way to deal with this?  At the moment, I'm just using something
like

  def unCR(f):
for line in f:
  yield line.replace('\r', '')

  f = file('input.csv', 'rb')
  for row in csv.reader(unCR(f)):
code_to_process(row)

but this throws away data that I'd really prefer to keep if possible.

I know 2.4 isn't exactly popular, and in an ideal world, I'd just
upgrade to a later 2.x version that does what I need.  Any old-time
2.4 pythonistas have sage advice for me?

-tkc


from cStringIO import StringIO
import csv
f = file('out.txt', 'wb')
w = csv.writer(f)
w.writerow(["One", "Two"])
w.writerow(["First\rSecond", "Third"])
f.close()

f = file('out.txt', 'rb')
r = csv.reader(f)
for i, row in enumerate(r): # works in 2.7, fails in 2.4
print repr(row)
f.close()


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with \r in CSV fields in Python2.4

2013-09-04 Thread Skip Montanaro
>   _csv.Error: newline inside string

How are the lines actually terminated, with \r\n or with just \n? If
it's just \n, what happens if you specify \n as the line terminator?

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Ferrous Cranus

Στις 4/9/2013 3:18 μμ, ο/η Heiko Wundram έγραψε:

Am 03.09.2013 09:48, schrieb Ferrous Cranus:

Si there a workaround for that please?

Yes, use/setup your own mailserver. Google will not allow you to send
as ("i.e., From:") an arbitrary address besides the one you've
authenticated as.


Hello Heiko,

You mean to ditch Google's SMTP server and use 'mail.superhost.gr' ?

Are you sure the same thing wont happen there too?

--
Webhost 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with \r in CSV fields in Python2.4

2013-09-04 Thread MRAB

On 04/09/2013 16:04, Tim Chase wrote:

I've got some old 2.4 code (requires an external lib that hasn't been
upgraded) that needs to process a CSV file where some of the values
contain \r characters.  It appears that in more recent versions (just
tested in 2.7; docs suggest this was changed in 2.5), Python does the
Right Thing™ and just creates values in the row containing that \r.
However, in 2.4, the csv module chokes on it with

   _csv.Error: newline inside string

as demoed by the example code at the bottom of this email.  What's the
best way to deal with this?  At the moment, I'm just using something
like

   def unCR(f):
 for line in f:
   yield line.replace('\r', '')

   f = file('input.csv', 'rb')
   for row in csv.reader(unCR(f)):
 code_to_process(row)

but this throws away data that I'd really prefer to keep if possible.

I know 2.4 isn't exactly popular, and in an ideal world, I'd just
upgrade to a later 2.x version that does what I need.  Any old-time
2.4 pythonistas have sage advice for me?


[snip]
You could try replacing the '\r' with another character that doesn't
appear elsewhere and then change it back afterwards.

MARKER = '\x01'

def cr_to_marker(f):
for line in f:
yield line.replace('\r', MARKER)

def marker_to_cr(item):
return item.replace(MARKER, '\r')

f = file('out.txt', 'rb')
r = csv.reader(cr_to_marker(f))
for i, row in enumerate(r): # works in 2.7, fails in 2.4
row = [marker_to_cr(item) for item in row]
print repr(row)
f.close()

Which OS are you using? On Windows the lines (rows) end with '\r\n', so
the last item of each row will end with '\r', which you'll need to
strip off. (That would be a problem only if the last item of a row
could end with '\r'.)

--
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with \r in CSV fields in Python2.4

2013-09-04 Thread Tim Chase
On 2013-09-04 10:20, Skip Montanaro wrote:
> >   _csv.Error: newline inside string
> 
> How are the lines actually terminated, with \r\n or with just \n? If
> it's just \n, what happens if you specify \n as the line terminator?

Unfortunately, the customer feed contains DOS newlines ("\r\n").

I'm not quite sure what """
Note
The reader is hard-coded to recognize either '\r' or '\n' as
end-of-line, and ignores lineterminator. This behavior may change in
the future.
""" means at [1].  Does that mean that efforts to change the
lineterminator don't have any effect? Or that you can't (currently)
specify anything other than "\r" or "\n"?  Though that is a bit
tangent to the actual issue.

-tkc


[1] http://docs.python.org/2/library/csv.html




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Ferrous Cranus

Στις 4/9/2013 3:38 μμ, ο/η Dave Angel έγραψε:

'file' isn't magic.  And again, it doesn't look at the filename, it
looks at the content.
So, you are saying that it looks a the content of the file and not of 
what encoding we used to save the file into?


But the contents have within:

f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
\xf3\xf\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')


so it should have said greek-iso and not ascii.

--
Webhost 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with \r in CSV fields in Python2.4

2013-09-04 Thread Tim Chase
On 2013-09-04 16:31, MRAB wrote:
> You could try replacing the '\r' with another character that doesn't
> appear elsewhere and then change it back afterwards.
> 
> MARKER = '\x01'
> 
> def cr_to_marker(f):
>  for line in f:
>  yield line.replace('\r', MARKER)
> 
> def marker_to_cr(item):
>  return item.replace(MARKER, '\r')
> 
> f = file('out.txt', 'rb')
> r = csv.reader(cr_to_marker(f))
> for i, row in enumerate(r): # works in 2.7, fails in 2.4
>  row = [marker_to_cr(item) for item in row]
>  print repr(row)
> f.close()

This works pretty well.  I'm not sure if there's a grave performance
penalty for mucking with strings so much, but at this point my
Care-o-Meter is barely registering, as long as it works.

> Which OS are you using? On Windows the lines (rows) end with
> '\r\n', so the last item of each row will end with '\r', which
> you'll need to strip off. (That would be a problem only if the last
> item of a row could end with '\r'.)

It's on Win32.

-tkc


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Beginner's guide to Python

2013-09-04 Thread Steve Hayes
On Wed, 4 Sep 2013 14:03:09 + (UTC), Grant Edwards
 wrote:

>On 2013-09-04, Steve Hayes  wrote:
>
>> Can anyone recommend a web site that gives a good beginner's guide to Python?
>
>http://www.greenteapress.com/thinkpython/
>
>> -- what kind of projects Python is good for
>
>Text processing
>Scientific data analysis and visualization
>Database stuff
>CRM
>Web sites
>Data communications
>Games
>System administration tools
>
>> -- what kind of projects it is not good for
>
>OS kernels and device drivers

Thanks very much for this, and to others who also replied. 



-- 
Steve Hayes from Tshwane, South Africa
Blog: http://khanya.wordpress.com
E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Piet van Oostrum
Heiko Wundram  writes:

> Am 03.09.2013 09:48, schrieb Ferrous Cranus:
>> Si there a workaround for that please?
>
> Yes, use/setup your own mailserver. Google will not allow you to send
> as ("i.e., From:") an arbitrary address besides the one you've
> authenticated as.

Actually, it does allow you. Only it adds the "Sender" header with your
email address.

The Sender field is to be used when the message is sent by another
person than the author of the message. For example when [email protected]
writes an email, but the actual sending of the email is done by his
secretary [email protected], the following headers should be present.

From: [email protected] Sender: [email protected]

The mail agent should display John as the originator of the email, and
replies should go to him, unless the user chooses differently. However,
when there is an error in the transmission, error messages should go to
Charles.

At least that is what the RFC's say. And I think that is the logical way
to do it. Now some Microsoft mail programs will send replies to Charles,
which is incorrect.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Piet van Oostrum
Ferrous Cranus  writes:

> I this hoq you mean?
[...]
>   
>   SUBJECT = u"Mail από τον επισκέπτη: ( %s )" % FROM
>   
>   MESSAGE = "\nFrom: %s\r\n" + "To: %s\r\n" + "Subject: 
> %s\r\n\r\n" % ( FROM, [TO], SUBJECT ) + MESSAGE + "\r\n"
>   MESSAGE = MESSAGE.encode('utf-8') 
[...]
> but now iam getting this error message:
>
> sendmail => %s 13-09-04 12:29:22 (, TypeError('not all 
> arguments converted during string formatting',),  0x7f0e432e1cb0>)
>
That is because you changed TO in [TO]. That causes the error.

** And the \n at the beginning shouldn't be there. **

MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, 
SUBJECT ) + MESSAGE + "\r\n"

You could even change that to:

MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n" % (FROM, 
TO, SUBJECT, MESSAGE)

which I think is nicer.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Piet van Oostrum
Ferrous Cranus  writes:


> I think it's logical to act that way.

I think it is not, see my other post on this subject.

> The real 'FROM' address that GMail uses to send mail from my 'mail.py'
> to some recipient is my real GMail's account address, and not the FROM
> address that any arbitrary poster posts in a html webform hwich can be
> totally fake, i.e. [email protected]

No, it's not, as I explained. Gmail uses the From address that you
specified, but added the Sender header with your Gmail account in it.
Now your email agent usesdisplays the Sender address as the From, which
is misleading.

> I believe any kind of mail client will be have this way.

No, my mail client doesn'tdo that.

> We need some way to dicth the Sender FROM string or alter it to the
> one uses in the webform.

You cannot ditch the Send from the sent email, as this is something
Gmail automatically provides. Maybe as some kind of spam detector, which
is reasonable. Actually providing the Sender in situations like this is
what the RFC requires, so Gmail is totally, completely correct in doing
this. The problem is completely on the receiving side, but Dave has told
you how to solve it.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Find out where a class is used throughout a program.

2013-09-04 Thread Azureaus
Hi All,
I'm fairly new to Python so please forgive me If I sound confused or include 
anything a bit irrelevant. I've had some great responses from this group 
already though so thanks.

I have a source file that is laid out roughly like

class:
class methods
methods 
init statement
class:
method

It doesn't seem to have a run method unlike other similar source files I have 
so it seems to be that this is being referenced from other files and is almost 
a 'utility file'.

To try and make this question as general as possible - is there a way of 
finding out / visualising where a particular class is called/used throughout a 
program? I need to find out the way in which these classes are being used and 
their typical input (and where the output from these are going) so I can have a 
play around and really figure out how it works. Without a run method to call, 
or an idea of expected input/output it's difficult. Also without some sort of 
trace it's difficult.

I spoke to colleague and was told to look into dir() method in a Python shell 
which I will do this evening but if anyone has any suggestions that would be 
great. Even better if you think this is what I'm after a quick example/use case 
would be even better. Or maybe I'm looking at this the wrong way and you can 
point me towards some docs?
Thanks for your help.
-- 
https://mail.python.org/mailman/listinfo/python-list


ICCEBS 2013 – Announce & Invitation

2013-09-04 Thread [email protected]
Dear Colleague,

We are pleased to announce the International Conference on Computational and 
Experimental Biomedical Sciences (ICCEBS2013 - www.fe.up.pt/~iccebs) in Ponta 
Delgada, S Miguel Island, Azores, October 20-22, 2013.
The use of more robust, affordable and efficient techniques and technologies 
with application in Biomedical Sciences is presently a subject of huge interest 
and demand, and ICCEBS is intended to be a privileged discussion forum to 
define their key stakeholders.
ICCEBS will bring together researchers from around the world representing 
several scientific fields related to Biomedical Sciences, including 
Engineering, Medicine, Biomechanics, Bioengineering, Biomaterials, Experimental 
Mechanics, Computer Sciences, Computational Mathematics, Hardware Developers 
and Manufactures, Electronic and Instrumentation and Materials Science.
TOPICS

In ICCEBS2013 will be considered topics of (not limited to):
- Analysis and diagnosis;
- Applications in medicine;
- Applications in veterinary;
- Artificial organs;
- Bioengineering;
- Biofluid;
- Biological microelectromechanical systems, Labs-on-chips and Life-chips;
- Biomaterials;
- Biomedical devices;
- Computational bio- imaging and visualization;
- Computational methods;
- Computer aided diagnosis;
- Computer assisted surgery;
- Experimental mechanics;
- Implantology;
- Medical robotics;
- Minimally invasive devices and techniques;
- Molecular and Cellular Biomechanics;
- Numeral methods;
- Prosthesis and orthosis;
- Rehabilitation;
- ImagingSignal processing and analysis;
- Simulation;
- Software development;
- Sustainability;
- Technical aids;
- Telemedicine;
- Tissue engineering;
- Virtual reality.

Due to your very interesting and key research activities, we would like to 
invite you to participate in ICCEBS2013 and share your expertize. Your 
contribution is welcomed, and we would be honored if you could accept this 
invitation.

INVITED KEYNOTES
“The Biomechanics Detective & Clues to Expensive Unintentional Injuries”
James A. Ashton-Miller - University of Michigan, USA “Experimental and 
numerical microstructural modelling of vascular tissues”
Estefanía Peña Baquedano - Universidad de Zaragoza, Spain “Modelling flow 
induced ATP/ADP concentration transport in patient-specific arteries”
Perumal Nithiarasu - Swansea University, UK

DATES
- Deadline for one page abstract submission: 30th September 2013;
- Authors’ notification: 5th October 2013;
- Deadline for full papers (not mandatory): 15th January 2014.

PUBLICATIONS
- Abstracts: All accepted abstracts will be distributed in a USB pen.
- Full Papers (not mandatory): The proceedings book of ICCEBS2013, with all 
full papers, will be published by Springer under the Book Series Lecture Notes 
in Computational Vision and Biomechanics (www.springer.com/series/8910).
- The organizers will prepare the publishing of a book with 20 invited works 
from the most important ones presented in ICCEBS2013 (extended versions). The 
book will be published by Springer under the Book Series Lecture Notes in 
Computational Vision and Biomechanics (www.springer.com/series/8910).
- Additionally, the organizers will encourage the submission of extended 
versions of the accepted works to related International Journals; particularly, 
for special journal issues dedicated to ICCEBS2013. Two already confirmed 
possibilities are: Computer Methods in Biomechanics and Biomedical Engineering: 
Imaging & Visualization (www.tandfonline.com/loi/tciv20) and International 
Journal for Computational Vision and Biomechanics (www.fe.up.pt/~ijcvb).

AWARD
A best work prize will be given by the conference organizers to the best work 
presented in ICCEBS2013.


Best wishes,
João Manuel R. S. Tavares, Universidade do Porto, Portugal ([email protected]) 
Renato Natal Jorge, Universidade do Porto, Portugal ([email protected]) (ICCEBS 
co-chairs)

PS. For more information, you are invited to visit the conference webpage at: 
www.fe.up.pt/~iccebs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Beginner's guide to Python

2013-09-04 Thread Grant Edwards
On 2013-09-04, Steve Hayes  wrote:

> Can anyone recommend a web site that gives a good beginner's guide to Python?

http://www.greenteapress.com/thinkpython/

> -- what kind of projects Python is good for

Text processing
Scientific data analysis and visualization
Database stuff
CRM
Web sites
Data communications
Games
System administration tools

> -- what kind of projects it is not good for

OS kernels and device drivers

> -- a simple explanation of how it works

That depends on what "it" is.

> -- a kind of beginner's tutotial and guide to its syntax

Google "python tutorial"

-- 
Grant Edwards   grant.b.edwardsYow! It's a lot of fun
  at   being alive ... I wonder if
  gmail.commy bed is made?!?
-- 
https://mail.python.org/mailman/listinfo/python-list


nozama-cloudsearch-service a local Amazon CloudSearch instance.

2013-09-04 Thread Oisin Mulvihill
Hello,

Have you ever wanted to test your app against a dev version of your
production CloudSearch? Is management saying budget constraints won't allow
this? Then Nozama CloudSearch is for you.

It is a light weight implementation of Amazon's CloudSearch service you can
run locally. Its has additional REST API features which allow inspection of
data in a way not available via Amazon CloudSearch.

It is BSD licensed and available now from pypi
https://pypi.python.org/pypi/nozama-cloudsearch-service:

  easy_install nozama-cloudsearch-service

Or from source code checkout from github here:

 * https://github.com/oisinmulvihill/nozama-cloudsearch

It also has documentation which it self hosts or can be seen on readthedocs:

 * https://nozama-cloudsearch.readthedocs.org/en/latest/index.html

I've implemented batch uploading and I'm working on search at present. I
thought I'd get this out early in case others are hitting against this. I'd
welcome contributions.

I don't intend this to be a replacement for Amazon CloudSearch. Its a
helper service I use it as part of a vagrant+puppet provisioned developer
environment. This emulates our production environment locally.

All the best,

Oisin
-- 
https://mail.python.org/mailman/listinfo/python-list


How to exit a cgi file after a download

2013-09-04 Thread Ferrous Cranus
Python help.

I use the following code in a cgi file
to give the client a download link to 
download a file.

---

print "%s" % (' Down 
Load ')



A click on "Down Load" opens a pop up browser 
window which allows the user to choose where 
to download the "Setup.zip" file, then after 
the download, the pop up window closes.

My problem is that I want the cgi form, which 
contains the link, to also close after the 
download.  The only way I can figure out to 
close the cgi window is to give the user a 
button to close it.  

Without closing it, the client can download 
again and forever if they choose to because 
the cgi window is open and the link is still 
active. 

I am trying to find a way to close the cgi 
file or call another file after the download 
without adding a close button and asking the 
client to close the window.

jd






-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Piet van Oostrum
Ferrous Cranus  writes:

> Στις 4/9/2013 3:18 μμ, ο/η Heiko Wundram έγραψε:
>> Am 03.09.2013 09:48, schrieb Ferrous Cranus:
>>> Si there a workaround for that please?
>> Yes, use/setup your own mailserver. Google will not allow you to send
>> as ("i.e., From:") an arbitrary address besides the one you've
>> authenticated as.
>
> Hello Heiko,
>
> You mean to ditch Google's SMTP server and use 'mail.superhost.gr' ?
>
> Are you sure the same thing wont happen there too?
>

Just try it. In your email program, let it show all headers. Or if you don't 
trust that, just let the mail be sent to me. I can see exactly how it is.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Downloading the feed using feedparser

2013-09-04 Thread Irmen de Jong
On 4-9-2013 13:12, mukesh tiwari wrote:
> Hello all, I am trying to download the feed of 
> http://blogs.forrester.com/feed but I
> am stuck with a problem.
> 
 import feedparser d = feedparser.parse('http://blogs.forrester.com/feed') 
 d.etag
> u'"1378291653-1"'
 d.modified
> 'Wed, 04 Sep 2013 10:47:33 +'
> 
 feedparser.parse('http://blogs.forrester.com/feed', etag=d.etag,
 modified=d.modified).status
> 200
> 
> When I am running this, should not this be 304 ( The content can't be change 
> so fast
> in a moment or this server is not configured properly ). If I rely on this 
> then
> whenever I run the code, I will download the content irrespective of content 
> changed
> or not. Could some one please suggest me how to avoid the duplicate download ?

No it's correct because repeatedly downloading that URL gives me a different 
etag and
last-modified header in the server's response. Their server is very likely to be
generating the data on the fly every time you retrieve that location. Why do 
you assume
this can't change so fast? It is very likely not a static file that is being 
retrieved,
but rather a piece of content that is generated for every request, by their 
server
application.


> 
> The below one is working fine so if I try to download again then I will get 
> 304
> response since no data is changed on server.
> 
 d = feedparser.parse("feed://feeds.huffingtonpost.com/HP/MostPopular") 
 d.etag

http, I pressume...

But yeah, that url gives the same etag and last-modified header in the 
response, when
repeatedly downloading it. This is probably a static file that is being updated 
once in
a while.

Irmen
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading from stdin first, then use curses

2013-09-04 Thread Veritatem Ignotam
I'd like to bump this. I asked a similar question a few weeks ago and
had no reply. Here's my question:

I'm fairly new to python and even newer to curses. Does any one have a
good solution for how to embed the output of a subprocess (ex.
subprocess.Popen("htop", stdout=subprocess.PIPE)) into an ncurses
window? So for example, the terminal window is broken up into quadrants
and the top right has htop running inside. I'd imagine this would
involve some kind of terminal emulation as the dimensions of the window
would need to be queried by htop.

If anyone could please point me in the right direction, I'd be very grateful

Thanks,

Ignotus


On 08/31/2013 04:31 AM, Timo Schmiade wrote:
> Hi again,
>
> sorry for replying to my own mail, but is there really no solution? Can
> curses really not be used in this situation?
>
> Thanks again,
>
> Timo
>
> On Sun, Aug 11, 2013 at 02:05:11PM +0200, Timo Schmiade wrote:
>> Hi all,
>>
>> I wrote a replacement for urlview to properly extract URLs from emails.
>> You can find the first draft here:
>>
>>   https://github.com/the-isz/pyurlview
>>
>> When I call it with an email file passed to the '-f' argument, it does
>> pretty much what I want already. However, I intend to use it in mutt,
>> which pipes the message to the program like so:
>>
>> macro pager \cu 'pyurlview.py' 'Follow links with 
>> pyurlview'
>>
>> The problem is rather obvious but - unfortunately - not so easy to solve:
>>
>> * The program reads the mail from stdin
>> * The terminal in which it runs is a pseudo-terminal (pipe)
>> * curses is not able to accept user input from the pseudo-terminal
>>
>> The question is:
>>
>> How do I read from stdin first and afterwards allow curses to read user
>> input?
>>
>> Thanks in advance and kind regards,
>>
>> Timo

-- 
https://mail.python.org/mailman/listinfo/python-list


How to exit a cgi file after a download.

2013-09-04 Thread inq1ltd
Python help.

I use the following code in a cgi file
to give the client a download link to 
download a file.

---

print "%s" % (' Down 
Load ')



A click on "Down Load" opens a pop up browser 
window which allows the user to choose where 
to download the "Setup.zip" file, then after 
the download, the pop up window closes.

My problem is that I want the cgi form, which 
contains the link, to also close after the 
download.  The only way I can figure out to 
close the cgi window is to give the user a 
button to close it.  

Without closing it, the client can download 
again and forever if they choose to because 
the cgi window is open and the link is still 
active. 

I am trying to find a way to close the cgi 
file or call another file after the download 
without adding a close button and asking the 
client to close the window.

jd



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find out where a class is used throughout a program.

2013-09-04 Thread dieter
Azureaus  writes:
> ...
> is there a way of finding out / visualising where a particular class is 
> called/used throughout a program?

I do not know a simple and reliable way.

When I face such a situation, I use standard operating system
utilities (e.g. "grep -r" under *nix) to search for occurrences of
the class name in the source tree. This often gives good
results when the class name has been well chosen.

Recently (within the last 2 months), I have seen the announcement
(on "...python.announce") of a tracing tool (I forgot the package's
name; maybe, it has been "CodeInspector"). When I have understood
the announcement correctly, then it traces concrete runs
and allows you to explore where objects (e.g. classes) have
been used *in these runs*.

-- 
https://mail.python.org/mailman/listinfo/python-list


Broadcasting TimeSeries

2013-09-04 Thread Davide Dalmasso
Hello,

I opened my Python Shell and I wrote the following:

>>> import numpy as np
>>> import pandas as pd

then I made a function

>>> def afunc(aframe):
return aframe - aframe.mean(axis=1)

and I defined a DataFrame with time as index

>>> A = 
>>> pd.DataFrame(np.random.randn(5,3),columns=['a','b','c'],index=pd.date_range(start='1984-12-20',periods=5))
>>> A
   a b c
1984-12-20 -0.257916 -0.137923 -0.669796
1984-12-21 -1.632874 -1.850365  1.571715
1984-12-22  1.185828 -0.149839 -1.565930
1984-12-23 -0.757311  0.034627  0.794608
1984-12-24  0.548785 -1.126786 -0.438457

now, if I call the function the following error is generated:

>>> afunc(A)
Traceback (most recent call last):
  File "", line 1, in 
afunc(A)
  File "", line 2, in afunc
return aframe - aframe.mean(axis=1)
  File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 217, in f
return self._combine_series(other, na_op, fill_value, axis, level)
  File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3601, in 
_combine_series
return self._combine_series_infer(other, func, fill_value)
  File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3619, in 
_combine_series_infer
FutureWarning)
  File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning
file.write(warnings.formatwarning(message, category, filename,
AttributeError: 'NoneType' object has no attribute 'write'

then I recall the same function (without any change) and the function works!

>>> afunc(A)
   a b c
1984-12-20  0.097295  0.217289 -0.314584
1984-12-21 -0.995699 -1.213190  2.208890
1984-12-22  1.362475  0.026808 -1.389283
1984-12-23 -0.781285  0.010652  0.770633
1984-12-24  0.887604 -0.787967 -0.099637

Why does this happen? Why I must call the function two times before it finally 
works?
How can I overcome this problem?

Many thanks in advance

Davide
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading from stdin first, then use curses

2013-09-04 Thread Antoon Pardon

Op 04-09-13 20:45, Veritatem Ignotam schreef:

I'd like to bump this. I asked a similar question a few weeks ago and
had no reply. Here's my question:

I'm fairly new to python and even newer to curses. Does any one have a
good solution for how to embed the output of a subprocess (ex.
subprocess.Popen("htop", stdout=subprocess.PIPE)) into an ncurses
window? So for example, the terminal window is broken up into quadrants
and the top right has htop running inside. I'd imagine this would
involve some kind of terminal emulation as the dimensions of the window
would need to be queried by htop.

If anyone could please point me in the right direction, I'd be very grateful


Search for pty in the python documentation.

--
Antoon Pardon.

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to exit a cgi file after a download.

2013-09-04 Thread Joel Goldstick
This same message comes up under one of Niko's many aliases.  Is this
another?  Why post twice?

On Wed, Sep 4, 2013 at 2:44 PM, inq1ltd  wrote:
> Python help.
>
> I use the following code in a cgi file
> to give the client a download link to
> download a file.
>
> ---
>
> print "%s" % (' Down
> Load ')
>
> 
>
> A click on "Down Load" opens a pop up browser
> window which allows the user to choose where
> to download the "Setup.zip" file, then after
> the download, the pop up window closes.
>
> My problem is that I want the cgi form, which
> contains the link, to also close after the
> download.  The only way I can figure out to
> close the cgi window is to give the user a
> button to close it.
>
> Without closing it, the client can download
> again and forever if they choose to because
> the cgi window is open and the link is still
> active.
>
> I am trying to find a way to close the cgi
> file or call another file after the download
> without adding a close button and asking the
> client to close the window.
>
> jd
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to exit a cgi file after a download

2013-09-04 Thread random832
On Wed, Sep 4, 2013, at 12:49, Ferrous Cranus wrote:
> Without closing it, the client can download 
> again and forever if they choose to because 
> the cgi window is open and the link is still 
> active. 

Why is this a problem? They usually won't want to, and if they do want
to (for example if they accidentally canceled the download) I don't see
why not to let them.

The solution should be to give them a unique download link that will
only work once (or only for a certain period of time), not to close the
window.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to exit a cgi file after a download

2013-09-04 Thread Benjamin Kaplan
On Sep 4, 2013 1:29 PM, "Ferrous Cranus"  wrote:
>
> Python help.
>
> I use the following code in a cgi file
> to give the client a download link to
> download a file.
>
> ---
>
> print "%s" % (' Down
> Load ')
>
> 
>
> A click on "Down Load" opens a pop up browser
> window which allows the user to choose where
> to download the "Setup.zip" file, then after
> the download, the pop up window closes.
>
> My problem is that I want the cgi form, which
> contains the link, to also close after the
> download.  The only way I can figure out to
> close the cgi window is to give the user a
> button to close it.
>
> Without closing it, the client can download
> again and forever if they choose to because
> the cgi window is open and the link is still
> active.
>
> I am trying to find a way to close the cgi
> file or call another file after the download
> without adding a close button and asking the
> client to close the window.
>
> jd
>
>

There is no such thing as a "cgi form" or "cgi window". Your cgi script
runs when the user requests a Web page, generates a page, and then ends. At
that point, python has stopped running. If your want the client's browser
window to close, that's not a python problem. If you want to invalidate the
download link after one successful download, you'll have to add a unique
identifier to the url and keep track of which identifiers are still valid.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find out where a class is used throughout a program.

2013-09-04 Thread Irmen de Jong
On 4-9-2013 22:08, dieter wrote:
> Azureaus  writes:
>> ...
>> is there a way of finding out / visualising where a particular class is 
>> called/used throughout a program?
> 
> I do not know a simple and reliable way.

Not 100% reliable, but arguably easier than reverting to simple text search 
tools, is
using a Python IDE such as PyCharm. It does a remarkable job most of the time 
to show
you the usages and dependencies of various items in your program. It does this 
by
actually parsing the source and not simply performing a text based search.

Irmen

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find out where a class is used throughout a program.

2013-09-04 Thread Terry Reedy

On 9/4/2013 4:08 PM, dieter wrote:

Azureaus  writes:

...
is there a way of finding out / visualising where a particular class is 
called/used throughout a program?



I do not know a simple and reliable way.

When I face such a situation, I use standard operating system
utilities (e.g. "grep -r" under *nix) to search for occurrences of
the class name in the source tree. This often gives good
results when the class name has been well chosen.


Idle has a built-in 'grep' called 'Find in Files' on the Edit menu. I 
use it routinely. By default, it searches for the current text 
selection, if there is one, in all files in the directory containing the 
current file (and subdirectories). Idle's grep uses Python's re module, 
so one does not have to learn another re dialect. So it works the same, 
with Unicode text, on all systems, including Windows, which does not 
come with grep. The (undocumented) limitation is that it searches each 
line separately, so it cannot search for multiline patterns. (I would 
not be surprised if grep does that same, as it also reports line numbers 
and multiple hits in a file.)



Recently (within the last 2 months), I have seen the announcement
(on "...python.announce") of a tracing tool (I forgot the package's
name; maybe, it has been "CodeInspector"). When I have understood
the announcement correctly, then it traces concrete runs
and allows you to explore where objects (e.g. classes) have
been used *in these runs*.



--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Piet van Oostrum
Piet van Oostrum  writes:

> Ferrous Cranus  writes:
>
>> I this hoq you mean?
> [...]
>>  
>>  SUBJECT = u"Mail από τον επισκέπτη: ( %s )" % FROM
>>  
>>  MESSAGE = "\nFrom: %s\r\n" + "To: %s\r\n" + "Subject: 
>> %s\r\n\r\n" % ( FROM, [TO], SUBJECT ) + MESSAGE + "\r\n"
>>  MESSAGE = MESSAGE.encode('utf-8') 
> [...]
>> but now iam getting this error message:
>>
>> sendmail => %s 13-09-04 12:29:22 (, TypeError('not all 
>> arguments converted during string formatting',), > 0x7f0e432e1cb0>)
>>
> That is because you changed TO in [TO]. That causes the error.
>
> ** And the \n at the beginning shouldn't be there. **
>
> MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, 
> SUBJECT ) + MESSAGE + "\r\n"
>
> You could even change that to:
>
> MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n" % 
> (FROM, TO, SUBJECT, MESSAGE)

There was another error in that line:

The string at the left of the % should be in parentheses, or be a single
string:

MESSAGE = ("From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n") % ( 
FROM, TO, SUBJECT, MESSAGE)

or

MESSAGE = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\r\n" % ( FROM, TO, 
SUBJECT, MESSAGE)

or even

MESSAGE = "From: %s\r\n" "To: %s\r\n" "Subject: %s\r\n\r\n%s\r\n" % ( FROM, TO, 
SUBJECT, MESSAGE)

Another note:

I did some expriments with Gmail and it seems that it also changes the
From header if the address given is not one that you registerd with your
gmail account. So it is even worse than I thought. (In practice I didn't
notice this because I have all the email addresses I use registered.)
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with \r in CSV fields in Python2.4

2013-09-04 Thread Terry Reedy

On 9/4/2013 11:04 AM, Tim Chase wrote:

I've got some old 2.4 code (requires an external lib that hasn't been
upgraded) that needs to process a CSV file where some of the values
contain \r characters.  It appears that in more recent versions (just
tested in 2.7; docs suggest this was changed in 2.5), Python does the
Right Thing™ and just creates values in the row containing that \r.
However, in 2.4, the csv module chokes on it with

   _csv.Error: newline inside string

as demoed by the example code at the bottom of this email.


While probably not necessary for this problem, one can use more that one 
Python version to solve a problem. For instance, You could use a current 
version to read the data and transform it so that it can be piped to 2.4 
code running in a subprocess.



 What's the
best way to deal with this?  At the moment, I'm just using something
like

   def unCR(f):
 for line in f:
   yield line.replace('\r', '')

   f = file('input.csv', 'rb')
   for row in csv.reader(unCR(f)):
 code_to_process(row)

but this throws away data that I'd really prefer to keep if possible.

I know 2.4 isn't exactly popular, and in an ideal world, I'd just
upgrade to a later 2.x version that does what I need.  Any old-time
2.4 pythonistas have sage advice for me?

-tkc


from cStringIO import StringIO
import csv
f = file('out.txt', 'wb')
w = csv.writer(f)
w.writerow(["One", "Two"])
w.writerow(["First\rSecond", "Third"])
f.close()

f = file('out.txt', 'rb')
r = csv.reader(f)
for i, row in enumerate(r): # works in 2.7, fails in 2.4
 print repr(row)
f.close()





--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: Broadcasting TimeSeries

2013-09-04 Thread Terry Reedy

On 9/4/2013 4:06 PM, Davide Dalmasso wrote:


I opened my Python Shell and I wrote the following:


This is with Idle. I believe you are running on Windows.


import numpy as np
import pandas as pd


then I made a function


def afunc(aframe):

 return aframe - aframe.mean(axis=1)

and I defined a DataFrame with time as index


A = 
pd.DataFrame(np.random.randn(5,3),columns=['a','b','c'],index=pd.date_range(start='1984-12-20',periods=5))
A

a b c
1984-12-20 -0.257916 -0.137923 -0.669796
1984-12-21 -1.632874 -1.850365  1.571715
1984-12-22  1.185828 -0.149839 -1.565930
1984-12-23 -0.757311  0.034627  0.794608
1984-12-24  0.548785 -1.126786 -0.438457

now, if I call the function the following error is generated:


afunc(A)

Traceback (most recent call last):
   File "", line 1, in 
 afunc(A)
   File "", line 2, in afunc
 return aframe - aframe.mean(axis=1)
   File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 217, in f
 return self._combine_series(other, na_op, fill_value, axis, level)
   File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3601, in 
_combine_series
 return self._combine_series_infer(other, func, fill_value)
   File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3619, in 
_combine_series_infer
 FutureWarning)
   File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning
 file.write(warnings.formatwarning(message, category, filename,
AttributeError: 'NoneType' object has no attribute 'write'


This was a bug in Idle when run directly on Windows, from Start or an 
icon. In this circumstance, there is no stderr stream to write to. I 
fixed it last June by catching the AttributeError and ignoring the 
warning. The fix will be in the next 2.7 and 3.3 releases and is in the 
3.4 releases (currently 0a1, soon 0a2).


The problem (of no stderr) is avoided now, while still using Idle, by 
starting Idle from a Command Prompt window (Start/Accessories):

  python -m idlelib
or by starting the standard interpreter (from Start or icon) and entering
  >>> import idlelib.idle


then I recall the same function (without any change) and the function works!


pandas must have a mechanism to only issue the warning once.


afunc(A)

a b c
1984-12-20  0.097295  0.217289 -0.314584
1984-12-21 -0.995699 -1.213190  2.208890
1984-12-22  1.362475  0.026808 -1.389283
1984-12-23 -0.781285  0.010652  0.770633
1984-12-24  0.887604 -0.787967 -0.099637

Why does this happen? Why I must call the function two times before it finally 
works?
How can I overcome this problem?


Answered, I believe.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


a dialog for throublshooting instead of print command pyqt

2013-09-04 Thread Mohsen Pahlevanzadeh
Dear all,

I need to a dialg such as aler in javascript in pyqt, my question is at:
http://stackoverflow.com/questions/18625406/a-dialog-for-throublshooting-instead-of-print-command-pyqt

Before answering, thank you...

Yours,
Mohsen

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to exit a cgi file after a download.

2013-09-04 Thread alex23

On 5/09/2013 5:42 AM, Joel Goldstick wrote:

This same message comes up under one of Niko's many aliases.  Is this
another?  Why post twice?


Because he's a troll.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Find out where a class is used throughout a program.

2013-09-04 Thread alex23

On 5/09/2013 2:32 AM, Azureaus wrote:

To try and make this question as general as possible - is there a way of 
finding out / visualising where a particular class is called/used throughout a 
program?


One option is to produce call graphs of the running code:

http://pycallgraph.slowchop.com/
--
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Dave Angel
On 4/9/2013 10:29, Ferrous Cranus wrote:

> Στις 4/9/2013 3:38 μμ, ο/η Dave Angel έγραψε:
>> 'file' isn't magic.  And again, it doesn't look at the filename, it
>> looks at the content.
> So, you are saying that it looks a the content of the file and not of 
> what encoding we used to save the file into?

That's right.  There's no place where your text editor stores the
encoding it used, so 'file' has to guess, based only on the content.
>
> But the contents have within:
>
> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 
> \xf3\xf\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')
>
> so it should have said greek-iso and not ascii.
>

No, that line is totally ASCII.  Only when it's EXECUTED by Python will
a non ASCII byte string object be created.  Like I said, 'file' doesn't
know the first thing about Python syntax, nor should it.

-- 
Signature file not found

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find out where a class is used throughout a program.

2013-09-04 Thread Roy Smith
In article <[email protected]>,
 Azureaus  wrote:

> To try and make this question as general as possible - is there a way of 
> finding out / visualising where a particular class is called/used throughout 
> a program? 

Sure.

$ cd 
$ find . -name "*.py" | xargs grep MyClassName.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to detect comment in source code file ?

2013-09-04 Thread Steven D'Aprano
On Wed, 04 Sep 2013 17:02:42 +1000, Ben Finney wrote:

> [email protected] writes:
> 
>> how works python interpreter for finding comment ?
> 
> It works as specified in the language reference. In particular, see
> http://docs.python.org/3/reference/lexical_analysis.html#comments>.
> 
>> if possible find nested comment ?
> 
> Python's comments are line-end comments only. The syntax does not allow
> multi-line nor nested comments.

While that's technically true, you can use bare strings as de facto 
comments. The compiler drops any bare strings it sees, so one can nest 
pseudo-comments like this:


do_this()
"""
do_that()
do_something()  # Make the widget work correctly.
'''
for x in range(5):
do_something_else()
'''
do_something_different()
"""


In the above, everything except do_this() is commented out by being 
turned into a string.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find out where a class is used throughout a program.

2013-09-04 Thread Steven D'Aprano
On Wed, 04 Sep 2013 09:32:28 -0700, Azureaus wrote:

> To try and make this question as general as possible - is there a way of
> finding out / visualising where a particular class is called/used
> throughout a program? I need to find out the way in which these classes
> are being used and their typical input (and where the output from these
> are going) so I can have a play around and really figure out how it
> works. Without a run method to call, or an idea of expected input/output
> it's difficult. Also without some sort of trace it's difficult.


Does the class not come with any documentation?

Start the Python interactive interpreter, and then enter these two lines:

import name_of_module
help(name_of_module.MyClassName)



where, of course, you replace name_of_module with the actual name of the 
module, and MyClassName with the actual name of the class.


If that doesn't solve your problem, you can use the searching tools of 
your choice to search for uses of the class. Open some source file in 
your editor and search for "MyClassName" and see what comes up. Repeat 
for any other source files you care about.

On a Linux or Mac system, you can use external tools. At the shell (not 
the Python shell, the operating system's shell) enter:

cd directory/where/my/source/code/lives
grep *.py MyClassName


or similar. Windows may have a similar tool, but I don't know what it is.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Steven D'Aprano
On Thu, 05 Sep 2013 00:17:36 +, Dave Angel wrote:

> On 4/9/2013 10:29, Ferrous Cranus wrote:
> 
>> Στις 4/9/2013 3:38 μμ, ο/η Dave Angel έγραψε:
>>> 'file' isn't magic.  And again, it doesn't look at the filename, it
>>> looks at the content.
>> So, you are saying that it looks a the content of the file and not of
>> what encoding we used to save the file into?
> 
> That's right.  There's no place where your text editor stores the
> encoding it used, so 'file' has to guess, based only on the content.

Correct. The thing that people often fail to understand is that there is 
no *reliable* way to store the encoding used for a text file in the text 
file itself. The encoding is *metadata*, not data: it is data about the 
data, and consequently it has to be stored "out of band". It has to be 
stored somewhere else, outside of the file.

In the case of text files, it is usually not stored anywhere at all. IBM 
mainframes assume that text files are using EBCDIC; modern Linux systems 
assume text files are UTF-8; old DOS applications assume text files are 
ASCII. Some text editors will try to guess the encoding, using various 
heuristics such as "if the file starts with \xFE\xFF it is UTF-16" but 
none of them are foolproof:

http://blogs.msdn.com/b/oldnewthing/archive/2004/03/24/95235.aspx

sometimes with amusing consequences:

http://www.hoax-slayer.com/bush-hid-the-facts-notepad.html



>> But the contents have within:
>>
>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1
>> \xf3\xf\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n')
>>
>> so it should have said greek-iso and not ascii.

But the above byte string is also valid ISO-8859-5 (Cyrillic):

'Жуэљѓєяќэяьсѓ\x0fѓєоьсєяђ\n'

ISO-8859-2 (Central European):

'śăíůóôďüíďěáó\x0fóôŢěáôďň\n'

and ISO-8859-4 (Baltic):

'ļãíųķôīüíīėáķ\x0fķôŪėáôīō\n'


Surely you don't expect the file utility to actually recognise that 
'Άγνωστοόνομασ\x0fστήματος\n' makes a valid Greek phrase while the others 
are not meaningful?



> No, that line is totally ASCII.  Only when it's EXECUTED by Python will
> a non ASCII byte string object be created.  Like I said, 'file' doesn't
> know the first thing about Python syntax, nor should it.

Technically, it's not ASCII, since ASCII only knows about bytes \x00 
through \x7F (decimal 0 through 127). That's why it isn't correct to 
describe Python bytes strings as "ASCII strings". They're byte strings 
that happen to be displayed as ASCII-plus-other-stuff.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Modest book on Python grahpics several years ago

2013-09-04 Thread W. eWatson
About 4-5 years ago, two authors (possibly one) wrote a book on Python 
for beginners. It was probably no more than 200 pages thick, and likely 
cost close to $25.  Several years later they wrote another book on 
Python graphics.  Does anyone recall the name of these books?  I don't 
think it was published by a well known publisher.

--
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Chris Angelico
On Thu, Sep 5, 2013 at 1:07 PM, Steven D'Aprano  wrote:
> Technically, it's not ASCII, since ASCII only knows about bytes \x00
> through \x7F (decimal 0 through 127). That's why it isn't correct to
> describe Python bytes strings as "ASCII strings". They're byte strings
> that happen to be displayed as ASCII-plus-other-stuff.

The line of code is itself entirely ASCII. The sequence REVERSE
SOLIDUS, LATIN SMALL LETTER X, LATIN SMALL LETTER B, DIGIT SIX is four
Unicode characters that are in the ASCII set. That Python interprets
them as representing the byte value 182 doesn't change that; the line
of code *is* ASCII.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Beginner's guide to Python

2013-09-04 Thread Andrew Berg
On 2013.09.04 22:39, Dennis Lee Bieber wrote:
> On Wed, 04 Sep 2013 07:26:47 +0200, Steve Hayes 
> declaimed the following:
> 
>>Can anyone recommend a web site that gives a good beginner's guide to Python?
>>
>>One that tells one, especially --
>>
>>-- what kind of projects Python is good for 
> 
>   So far as I know, Python is "Turing-complete" -- it can be used for
> anything... 
So is Brainfuck, but I wouldn't say it's good for *any* project...

-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.2
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Beginner's guide to Python

2013-09-04 Thread Chris Angelico
On Thu, Sep 5, 2013 at 2:03 PM, Andrew Berg  wrote:
> On 2013.09.04 22:39, Dennis Lee Bieber wrote:
>> On Wed, 04 Sep 2013 07:26:47 +0200, Steve Hayes 
>> declaimed the following:
>>
>>>Can anyone recommend a web site that gives a good beginner's guide to Python?
>>>
>>>One that tells one, especially --
>>>
>>>-- what kind of projects Python is good for
>>
>>   So far as I know, Python is "Turing-complete" -- it can be used for
>> anything...
> So is Brainfuck, but I wouldn't say it's good for *any* project...

There are always surprises. A few years ago (okay, a good few now) I
was gobsmacked to learn that JavaScript, which I'd always thought was
for web browsers only, could be used for writing web *servers*. And
the inverse is true, too - Pike, a language specifically designed for
building servers (specifically MUDs - plain text), has bindings for
GTK, so it can be used for writing graphical desktop applications.

But there are definite goals and philosophies that affect whether a
language is good for something or not. Python is extremely well suited
to short scripts that do one tiny thing and immediately shut down,
because it has an absolute minimum of boilerplate; other languages,
where you have to wrap your code up in "int main() { ... }" are less
suited to that. On the flip side, Python's object model tends to be
less well suited to massive scaling; I don't know about PyPy and other
Pythons, but certainly CPython isn't designed to run on arbitrary
numbers of cores (once you go to multiprocessing, you then need to
worry about IPC; if you work in a lower level language like C, you can
use threads and directly access each other's memory). "Everything is
permissible" - but not everything is constructive. [1] Sometimes
you're fighting the language rather than working with it.

ChrisA

[1] Did you know that the Corinthian church needed advice on
programming? First letter, tenth chapter, twenty-third verse.
-- 
https://mail.python.org/mailman/listinfo/python-list


NameError: global name '' is not defined , but a bit differences

2013-09-04 Thread Mohsen Pahlevanzadeh
Dear all , 

i get the error :

NameError: global name 'ui' is not defined

Complete question is at :
http://stackoverflow.com/questions/18627608/nameerror-global-name-is-not-defined-but-differences

Before answering, Thank you for your attention...!


Yours,
Mohsen


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Cameron Simpson
On 04Sep2013 12:38, Dave Angel  wrote:
| 'file' isn't magic.

Chuckle...

| What heuristics it uses, I don't know, but it has
| hundreds of them.

... because the file of heuristics is /usr/share/file/magic :-)
See "man 5 magic".

Cheers,
-- 
Cameron Simpson 

A vacuum is a hell of a lot better than some of the stuff that nature
replaces it with.   - Tenessee Williams
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError issue

2013-09-04 Thread Steven D'Aprano
On Thu, 05 Sep 2013 13:59:17 +1000, Chris Angelico wrote:

> On Thu, Sep 5, 2013 at 1:07 PM, Steven D'Aprano 
> wrote:
>> Technically, it's not ASCII, since ASCII only knows about bytes \x00
>> through \x7F (decimal 0 through 127). That's why it isn't correct to
>> describe Python bytes strings as "ASCII strings". They're byte strings
>> that happen to be displayed as ASCII-plus-other-stuff.
> 
> The line of code is itself entirely ASCII. 
..^^


Ah, so it is. Sorry, I got confused about what was being spoken about. 
Apologies to Dave for casting aspersions on his knowledge :-)




-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to detect comment in source code file ?

2013-09-04 Thread Vincent Vande Vyvre

Le 04/09/2013 08:05, [email protected] a écrit :

how works python interpreter for finding comment ?
if possible find nested comment ?

If you need to find it yourself, you can use the module tokenize.

ex.:
---
import tokenize
from StringIO import StringIO

script = "# importing comment\nfrom foo import baz"\
"if baz.vers < 2:\nAUTO = False # Retrocompatibility"

def find_comment():
print script
cmt = tokenize.COMMENT
tokens = tokenize.generate_tokens(StringIO(script).readline)
for typ, _, begin, _, _ in tokens:
if typ == cmt:
print 'Find comment line %s at column %s' % begin

find_comment()
---

(for Python 3 import StringIO from io)

--
Vincent V.V.
Oqapy  . Qarte 
 . PaQager 

--
https://mail.python.org/mailman/listinfo/python-list


Re: NameError: global name '' is not defined , but a bit differences

2013-09-04 Thread Benjamin Kaplan
On Wed, Sep 4, 2013 at 9:17 PM, Mohsen Pahlevanzadeh
 wrote:
> Dear all ,
>
> i get the error :
>
> NameError: global name 'ui' is not defined
>
> Complete question is at :
> http://stackoverflow.com/questions/18627608/nameerror-global-name-is-not-defined-but-differences
>
> Before answering, Thank you for your attention...!
>
>
> Yours,
> Mohsen
>
>

Please don't just post a link to Stack Overflow for your questions. It
means that if Stack Overflow ever shuts down, this question is useless
to anyone else looking at this post and also adds an extra step to
anyone on this list wanting to answer your question- we're helping you
in our spare time because we want to help people with these things.
Please don't make us do extra work to help you.

Just a note- doing a "from module import *" is considered poor coding
style because it makes it difficult to figure out where all the names
are coming from, especially if you start doing multiple import *s in a
single code file. Either explicitly import the names you need ("from
ui.interface.interface import InterfaceCodes") or import the module
without adding the names to the local namespace ("import
ui.interface.interface")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-04 Thread Ferrous Cranus

Στις 4/9/2013 7:16 μμ, ο/η Piet van Oostrum έγραψε:

Ferrous Cranus  writes:


I this hoq you mean?

[...]


SUBJECT = u"Mail από τον επισκέπτη: ( %s )" % FROM

MESSAGE = "\nFrom: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" 
% ( FROM, [TO], SUBJECT ) + MESSAGE + "\r\n"
MESSAGE = MESSAGE.encode('utf-8')

[...]

but now iam getting this error message:

sendmail => %s 13-09-04 12:29:22 (, TypeError('not all arguments 
converted during string formatting',), )


That is because you changed TO in [TO]. That causes the error.

** And the \n at the beginning shouldn't be there. **

MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, SUBJECT ) + 
MESSAGE + "\r\n"

You could even change that to:

MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n" % (FROM, 
TO, SUBJECT, MESSAGE)

which I think is nicer.





Now i have it like you said:


UBJECT = u"SuperHost Guest Mail από τον [ %s ]" % FROM

MESSAGE = "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" % (FROM, TO, 
SUBJECT, MESSAGE)

MESSAGE = MESSAGE.encode('utf-8')


but i still get the same error messgae

i use '\n' though and not '\r\n' but this is not an issue.
--
Webhost 
--
https://mail.python.org/mailman/listinfo/python-list