Re: About executable

2013-08-26 Thread Fábio Santos
On 25 Aug 2013 21:47, "Luis José Novoa"  wrote:
>
> Hi All. I am trying to create an executable file containing an
optimization code using the pyomo package for optimization modeling along
with ither packages like Numpy. When using py2exe to perform the task it
generates the executable file, but when I try to run it it reports: Import
Error: No module named pyomo.
>
> Any guidance on how to solve this problem would be really appreciated.

Have you checked py2exe's documentation? Bundling external modules with an
exe ought to be a very, very, common task. If all else fails, you can try
cx_freeze too. I think it generates windows executables too.

Good luck!
-- 
http://mail.python.org/mailman/listinfo/python-list


Resetting state of http.client/httplib HTTPSConnection objects

2013-08-26 Thread Chris Down
This is a crosspost from python-tutor upon suggestion.

I am experiencing intermittent issues where an exception will be raised when
calling getresponse(), which makes the entire connection stuck in Request-sent
state. Is it possible to reset to idle state somehow without reinstantiating
the HTTPSConnection? I ideally want to keep the connection to the server, and
just reset the state to idle so that I can make another request (like you would
usually do by calling getresponse()).

>>> a.conn

>>> a.conn.getresponse()
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib64/python3.3/http/client.py", line 1143, in getresponse
response.begin()
  File "/usr/lib64/python3.3/http/client.py", line 354, in begin
version, status, reason = self._read_status()
  File "/usr/lib64/python3.3/http/client.py", line 324, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: ''
>>> a.conn.request("GET", "foo")
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib64/python3.3/http/client.py", line 1061, in request
self._send_request(method, url, body, headers)
  File "/usr/lib64/python3.3/http/client.py", line 1089, in _send_request
self.putrequest(method, url, **skips)
  File "/usr/lib64/python3.3/http/client.py", line 944, in putrequest
raise CannotSendRequest(self.__state)
http.client.CannotSendRequest: Request-sent


pgpkTDZASsW7A.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Peasy: an easy but powerful parser

2013-08-26 Thread Simeon Chaos
  I've released Peasy, which is an easy but powerful parser. 
  Peasy brings a new method to write the parser. with Peasy, you write the 
parser by hand, just like to write any other kind of program. Do not be 
confused by "by hand", with the method brought by Peasy, it's easier and more 
powerful than using other tools or libraries. 
  Peasy presents itself as a module of single file. To use Peasy, copy peasy.py 
to your project, read it, modify it, write the grammar rules, and remove any 
unnecessary stuffs in Peasy, and parse with the grammar. 
  Peasy has an simple, elegant and fast support for direct/indirect left 
recursive grammar, See [here]( 
http://chaosim.github.io/peasy/doc/peasy.html#peasysample ) for a concrete 
sample. 
  The [annotated code]( http://chaosim.github.io/peasy/doc/pypeasy.html ) is 
best document for Peasy at the moment.
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting request's source site

2013-08-26 Thread Guy Tamir
Hi all,

I was wondering how i can get the source from which the request came from.
If a user posted a link that directs to my server on facebook i'd like to know 
that a specific click was from facebook or twitter etc..

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking homogeneity of Array using List in Python

2013-08-26 Thread Neil Cerutti
On 2013-08-25, sahil301...@gmail.com  wrote:
> I am unable to check homogeneity of Array.
> I have take Array type Int to be default for my code.
>
> Instead of getting Error on NON-INT Values.
> I want to take input as string.
> Then check if all input is in (0-9) form, I typecast it into int and Accept.
> Else, I would like to skip that input.
>
> eg. my input is ['1', ' ', 'asdasd231231', '1213asasd', '43242']
> I want it to be interpreted as:
> [1, [None], [None], [None], 43242]
>
> NOTE: NO INBUILT FUNCTION BE USED.

Impossible. I think.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting request's source site

2013-08-26 Thread Steven D'Aprano
On Mon, 26 Aug 2013 06:10:41 -0700, Guy Tamir wrote:

> Hi all,
> 
> I was wondering how i can get the source from which the request came
> from. If a user posted a link that directs to my server on facebook i'd
> like to know that a specific click was from facebook or twitter etc..

That would be the "referer" header in the HTTP request. (Note that it is 
an accidental misspelling of "referrer".) Including a referrer is not 
compulsory, so be prepared for it not to be available.



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


Re: Getting request's source site

2013-08-26 Thread Joel Goldstick
On Mon, Aug 26, 2013 at 11:03 AM, Guy Tamir  wrote:
> On Monday, August 26, 2013 5:25:49 PM UTC+3, Steven D'Aprano wrote:
>> On Mon, 26 Aug 2013 06:10:41 -0700, Guy Tamir wrote:
>>
>>
>>
>> > Hi all,
>>
>> >
>>
>> > I was wondering how i can get the source from which the request came
>>
>> > from. If a user posted a link that directs to my server on facebook i'd
>>
>> > like to know that a specific click was from facebook or twitter etc..
>>
>>
>>
>> That would be the "referer" header in the HTTP request. (Note that it is
>>
>> an accidental misspelling of "referrer".) Including a referrer is not
>>
>> compulsory, so be prepared for it not to be available.
>>
>>
>>
>>
>>
>>
>>
>> --
>>
>> Steven
>
> Thanks for reply,
> In what cases will i have this header? is there something i can do to enforce 
> having it?
> Are there any other ways?
> --

You can look in the server logs if you have them available.  If the
visitor supplied a referer value in the header, it will be in the log.
 You don't have any say in this from your end.

If you are the creator of your own website you might like to add
google analytics to your pages.  This is done with a little javascript
that google provides.

Although there may be a python angle to your question, it isn't apparent yet.


> http://mail.python.org/mailman/listinfo/python-list



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


Re: python eval function

2013-08-26 Thread Mohsen Pahlevanzadeh
On Mon, 2013-08-26 at 00:55 +, Steven D'Aprano wrote:
> On Sun, 25 Aug 2013 23:48:34 +0430, Mohsen Pahlevanzadeh wrote:
> 
> > Dear all,
> > 
> > eval doesn't run my code at the following link:
> > http://stackoverflow.com/questions/18432198/eval-function-doesnt-work-
> in-python
> 
> 
> Are you asking a question or just sharing a useful link?
> 
> 
> 
> > Thank you before your answer...
> 
> What question do you want us to answer? The question on Stackoverflow has 
> already been answered correctly: there is no need to use eval (or exec) 
> for this basic task. 
> 
> Also, you're not writing C code. Get rid of the semi-colons, they are 
> just a waste of time, and make you look like an incompetent programmer.
> 
> Using exec is not the right solution. That is unsafe, if the field name 
> and content come from a database or external input, your code now has a 
> *serious* Code Injection vulnerability. AND it is slow. So you have 
> written slow, unsafe code. Get rid of it, and use setattr like you have 
> already been told:
> 
> setattr(self, fieldName, fieldValue)
> 
> 
> 
> -- 
> Steven
I didn't post a useful link,i questioned my problem.Of course, At first
i put it @stackoverflow then post its link for the following idea:
1. collecting votes for me and someone answered.
2. If anyone have my question in future, can use it.
Thank you for answer.

--mohsen

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


Re: Getting request's source site

2013-08-26 Thread Guy Tamir
On Monday, August 26, 2013 5:25:49 PM UTC+3, Steven D'Aprano wrote:
> On Mon, 26 Aug 2013 06:10:41 -0700, Guy Tamir wrote:
> 
> 
> 
> > Hi all,
> 
> > 
> 
> > I was wondering how i can get the source from which the request came
> 
> > from. If a user posted a link that directs to my server on facebook i'd
> 
> > like to know that a specific click was from facebook or twitter etc..
> 
> 
> 
> That would be the "referer" header in the HTTP request. (Note that it is 
> 
> an accidental misspelling of "referrer".) Including a referrer is not 
> 
> compulsory, so be prepared for it not to be available.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Thanks for reply,
In what cases will i have this header? is there something i can do to enforce 
having it?
Are there any other ways?
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Global variable

2013-08-26 Thread chandan kumar
Hi all,

Please see the below code,in which i'm verifying the global value in python.

CHK=10

def test1():
print "Value of  CHK in test1",CHK

def test2():
CHK=40
print "Value of CHK  in test2",CHK
test1()

def test3():
global CHK 
test2()

test3()

When i ran above code ,I'm getting vlaue of CHK as 40 in test2 method and 10 in 
test1 method
Can somone explain me why the value of CHK  is different in method test1 and 
test2.

Best Regards,
Chandan


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


Re: Python Global variable

2013-08-26 Thread Joel Goldstick
On Mon, Aug 26, 2013 at 5:54 AM, chandan kumar  wrote:
> Hi all,
>
> Please see the below code,in which i'm verifying the global value in python.
>
> CHK=10
>
> def test1():
> print "Value of  CHK in test1",CHK
>
> def test2():
> CHK=40
> print "Value of CHK  in test2",CHK
> test1()
>
> def test3():
> global CHK
> test2()
>
> test3()
>
> When i ran above code ,I'm getting vlaue of CHK as 40 in test2 method and 10 
> in test1 method
> Can somone explain me why the value of CHK  is different in method test1 and 
> test2.

First, you are using incorrect terminology.  You are defining
functions here, not methods.  A method is a 'function' that is
contained within a class.

Now, on to your question.

You define CHK = 10 at the top of your code.  CHK is a name defined
within the global namespace of your file.

In test1 you print CHK which will be the value of the global CHK.
This is because, in python if a referenced name isn't present in the
most immediate namespace (test1), it will look in the successive
containing namespaces. to find the value.

In test2 you create a new name CHK which is not the same as the outer
CHK.  The test2 CHK is only visible within the function.  You assign
it the value 40.  When it executes, it prints 40.

In test3 you let test3 know that CHK refers to the global (outer) name
CHK.  However when you call test2, you do it with no parameters.
test2 knows nothing of your test3 internal names.

You need to look up python namespaces, and scoping.  I believe these
are covered in the python.org tutorial.  Be aware that if you learned
another language (C, Java) that names will confuse you for a while in
python.
>
> Best Regards,
> Chandan
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list



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


Re: Python Global variable

2013-08-26 Thread MRAB

On 26/08/2013 10:54, chandan kumar wrote:

Hi all,

Please see the below code,in which i'm verifying the global value in python.

CHK=10

def test1():
 print "Value of  CHK in test1",CHK

def test2():
 CHK=40
 print "Value of CHK  in test2",CHK
 test1()

def test3():
 global CHK
 test2()

test3()

When i ran above code ,I'm getting vlaue of CHK as 40 in test2 method and 10 in 
test1 method
Can somone explain me why the value of CHK  is different in method test1 and 
test2.


In a function, if you bind to a name then Python assumes that the name
is local to that function unless you declare that it's global.

In test1, you refer to 'CHK' but don't bind to it, therefore it's
global.

In test2, you bind to 'CHK' with 'CHK=40', and you haven't declared
that it's global, therefore it's local to test2.

In test3, you declare that 'CHK' is global, but don't mention it
anywhere else in that function, so it serves no purpose.
--
http://mail.python.org/mailman/listinfo/python-list


optparse question (python 2.6)

2013-08-26 Thread Andy Kannberg
Hi python-guru's,

I am new to Python, coming from a long history of Unix/linux shell
programming.
I am creating a Python script (In Python 2.6)  which should be able to read
command line options and arguments.
So far, I figured out how to do that with optparse. I can add options (and
arguments ) .
There are about 7 options that can be selected.

However, I can't seem to figure out how to force that only one option is
allowed when the script is invoked. In other words: How to restrict the
script to accept only one of the available options ?

cheers,
Andy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optparse question (python 2.6)

2013-08-26 Thread Peter Otten
Andy Kannberg wrote:

> Hi python-guru's,
> 
> I am new to Python, coming from a long history of Unix/linux shell
> programming.
> I am creating a Python script (In Python 2.6)  which should be able to
> read command line options and arguments.
> So far, I figured out how to do that with optparse. I can add options (and
> arguments ) .
> There are about 7 options that can be selected.
> 
> However, I can't seem to figure out how to force that only one option is
> allowed when the script is invoked. In other words: How to restrict the
> script to accept only one of the available options ?

You have to do it manually, like in the example

http://docs.python.org/2.6/library/optparse.html#how-optparse-handles-errors

if options.a and options.b:
parser.error("options -a and -b are mutually exclusive")

which could be generalized to (untested)

option_names = ["foo", "bar", "baz", ...]
toggled_options = [name for name in option_names if getattr(options, name)]
if len(toggled_options) > 1:
s = repr(toggled_options).strip("[]")
parser.error("options %s are mutually exclusive" % s)

If you are not restricted to the standard library use

https://pypi.python.org/pypi/argparse

which was added to the stdlib in 2.7 and has "mutually exclusive groups", 
see

http://docs.python.org/2/library/argparse.html#mutual-exclusion

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


Re: Getting request's source site

2013-08-26 Thread random832
On Mon, Aug 26, 2013, at 11:03, Guy Tamir wrote:
> Thanks for reply,
> In what cases will i have this header?

In practice, you'll usually have it, except in cases where the user has
bookmarked your site, typed/pasted the URL directly, had it opened by an
external program, or taken action to block referers from being sent
(this last one is uncommon)

> is there something i can do to
> enforce having it?

You can refuse to serve the content if it's not present. But this will
annoy users since they can't bookmark it or open it from an external
program.
-- 
http://mail.python.org/mailman/listinfo/python-list


How come StopIteration.__base__ is not BaseException?

2013-08-26 Thread Marco Buttu
Since StopIteration is not an error, how come does it inherit directly 
from Exception and not from BaseException?


Thanks in advance, Marco
--
Marco
--
http://mail.python.org/mailman/listinfo/python-list


How to check client shutdown?

2013-08-26 Thread Paul Pittlerson
I'm currently learning about the socket module. My question is how can I detect 
if a connection is closed from the other side, for example a KeyboardInterrupt 
as I frequently use. My code below:

##
#server script:

class client(threading.Thread):
def __init__(self, connection):
super(client, self).__init__()

self.recv = connection.recv

print dir(connection)

def start(self):
self.run()

def run(self):
while True:
data = self.recv(2000)

if data:
msg = self.decode(data)
print msg
#break;

def decode(self, data):
return pickle.loads(data)


class bullet_server:
def __init__(self):
self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

def start(self):
server_address = ("localhost", 9006)
print '/--server running--/'
print server_address 
self.server.bind(server_address)
self.server.listen(5)

while True:
connection, client_address = self.server.accept()

c = client(connection)
c.start()


if __name__ == '__main__':
server = bullet_server()
server.start()


##
#client script:

# set IP and port
host = '127.0.0.1'
port = 9006

# connect to server
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect((host, port))

def loop():
print 'Enter message:'
msg = raw_input()
encoded = pickle.dumps(msg)
connection.send(encoded)
loop()

loop()


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


Re: How to check client shutdown?

2013-08-26 Thread Chris Angelico
On Tue, Aug 27, 2013 at 5:45 AM, Paul Pittlerson  wrote:
> I'm currently learning about the socket module. My question is how can I 
> detect if a connection is closed from the other side, for example a 
> KeyboardInterrupt as I frequently use. My code below:
>

Once the remote end has terminated (as it will presumably do in this
case), any attempt to write to the socket will eventually result in an
error. You should be able to see that by simple experimentation. Be
aware that it might take a bit of time for the error to filter back to
you; it depends on whether the remote end actually sends back a RST
(reset) packet or not. (In a sane system, hitting Ctrl-C should result
in a clean shutdown and proper socket closure, but your server needs
to handle the case where it doesn't get one.) Play around with it, you
should be able to figure out what it's doing for you.

A couple of tangential comments about your script:

> ##
> #server script:
>
> def decode(self, data):
> return pickle.loads(data)

MAJOR security issue here. You are taking data from a networked source
and running it through a trusting system (pickle). This is NOT
recommended.

Also: You're using a stream socket, and depending - I think - on
getting an entire message in a single read() call. This is definitely
not guaranteed, though when you're working with localhost it's likely
to be true. To make this reliable, you'll need to do something like
prefix the message with its length (eg a Hollerith string), or use
some system like JSON that lets you detect the end of the message.

>From the client:

> def loop():
> print 'Enter message:'
> msg = raw_input()
> encoded = pickle.dumps(msg)
> connection.send(encoded)
> loop()
>
> loop()

Why recurse? Why not simply loop? No Python has tail-call optimization
(as far as I know), so this will eventually blow up with a
RuntimeError: maximum recursion depth exceeded.

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


Re: How come StopIteration.__base__ is not BaseException?

2013-08-26 Thread random832
On Mon, Aug 26, 2013, at 15:37, Marco Buttu wrote:
> Since StopIteration is not an error, how come does it inherit directly 
> from Exception and not from BaseException?

The reason KeyboardInterrupt and SystemExit inherit from BaseException
is because you often want them to escape (allowing the program to quit)
from code that would otherwise catch them (by catching Exception). On
the contrary, StopIteration is almost always used in a context that
catches it specifically.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which DLL did fail to load

2013-08-26 Thread Miki Tebeka
>  Wouldn't it  
> better to add a feature to Python to write the name of DLL which load 
> has been failed?

If you start Python with the -v (verbose) flag, you can see all the calls to 
dlopen.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to check client shutdown?

2013-08-26 Thread MRAB

On 26/08/2013 20:45, Paul Pittlerson wrote:

I'm currently learning about the socket module. My question is how
can I detect if a connection is closed from the other side, for
example a KeyboardInterrupt as I frequently use. My code below:


[snip]
When reading from a socket, it'll return as much data as is available,
up to the given limit if specified.

If _no_ data is available, then it'll block, unless the socket has been
closed at the other end, in which case it'll return zero bytes (an
empty bytestring).
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to check client shutdown?

2013-08-26 Thread Grant Edwards
On 2013-08-26, Paul Pittlerson  wrote:

> I'm currently learning about the socket module. My question is how
> can I detect if a connection is closed from the other side,

recv() will return an empty value of ''.

send() will eventually throw an exception.  [You may be able to call
send() once or twice after the connection has been closed without
getting the exception.] On Linux the exception is socket.error with
errno 32 (broken pipe).

-- 
Grant Edwards   grant.b.edwardsYow! Is this an out-take
  at   from the "BRADY BUNCH"?
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking homogeneity of Array using List in Python

2013-08-26 Thread Joshua Landau
On 26 August 2013 14:49, Neil Cerutti  wrote:
> On 2013-08-25, sahil301...@gmail.com  wrote:
>>
>> eg. my input is ['1', ' ', 'asdasd231231', '1213asasd', '43242']
>> I want it to be interpreted as:
>> [1, [None], [None], [None], 43242]
>>
>> NOTE: NO INBUILT FUNCTION BE USED.
>
> Impossible. I think.

class BoilerplateToStopCheating:
def __init__(self):
"""Factor things out to prevent cheating."""
self.digit_to_number = {"0":0, "1":1, "2":2, "3":3, "4":4,
"5":5, "6":6, "7":7, "8":8, "9":9}

def __call__(self, items):
def fudging():
"""More cheat-fudging."""
for item in items:
try:
as_number = 0
for char in item:
as_number *= 10
as_number += self.digit_to_number[char]
yield as_number

except KeyError:
yield [None]

[*z] = fudging()
return z

converter = BoilerplateToStopCheating()

# Can't use "print"...
# Erm...
converter(['1', ' ', 'asdasd231231', '1213asasd', '43242'])
# Output: [1, [None], [None], [None], 43242]
-- 
http://mail.python.org/mailman/listinfo/python-list


Imaplib & Gmail - cannot move from inbox to custom folder (message remains in both)

2013-08-26 Thread rob
I am using Imaplib and connecting to a Gmail account.  I am issuing commands to 
copy the email to a custom folder then issuing delete.  After expunge message 
still remains in inbox and customer folder.

# COPY EMAIL TO FOLDER
copyStatus = m.copy(emailid, 'CIRIMPORTED')
print 'id of message copied is: %s status: %s' % (emailid,copyStatus)
 
# SET THE MESSAGE TO HAVE '\Deleted' FLAG (EXPUNGE WILL COMPLETE DELETE 
PROCESS)
storeStatus = m.store(emailid,"+FLAGS", r'(\Deleted)')
print 'id of message stored is: %s status: %s %s' % 
(emailid,storeStatus[0],storeStatus[1])
#print '**'

#DELETES ANY EMAIL MARKED \Deleted
m.expunge()
m.close()
m.logout()

Does anyone have any imaplib code the works with Gmail to move from inbox to 
another folder?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Imaplib & Gmail - cannot move from inbox to custom folder (message remains in both)

2013-08-26 Thread MRAB

On 27/08/2013 00:34, r...@attoenterprises.com wrote:

I am using Imaplib and connecting to a Gmail account.  I am issuing commands to 
copy the email to a custom folder then issuing delete.  After expunge message 
still remains in inbox and customer folder.

 # COPY EMAIL TO FOLDER
 copyStatus = m.copy(emailid, 'CIRIMPORTED')
 print 'id of message copied is: %s status: %s' % (emailid,copyStatus)

 # SET THE MESSAGE TO HAVE '\Deleted' FLAG (EXPUNGE WILL COMPLETE 
DELETE PROCESS)
 storeStatus = m.store(emailid,"+FLAGS", r'(\Deleted)')
 print 'id of message stored is: %s status: %s %s' % 
(emailid,storeStatus[0],storeStatus[1])
 #print '**'

 #DELETES ANY EMAIL MARKED \Deleted
 m.expunge()
 m.close()
 m.logout()

Does anyone have any imaplib code the works with Gmail to move from inbox to 
another folder?


There's an example in docs which says:

M.store(num, '+FLAGS', '\\Deleted')

You have:

m.store(emailid,"+FLAGS", r'(\Deleted)')

Could it be that the flags should be r'\Deleted'?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Imaplib & Gmail - cannot move from inbox to custom folder (message remains in both)

2013-08-26 Thread rob
On Monday, August 26, 2013 5:56:09 PM UTC-6, MRAB wrote:
> On 27/08/2013 00:34, r...@attoenterprises.com wrote:
> 
> > I am using Imaplib and connecting to a Gmail account.  I am issuing 
> > commands to copy the email to a custom folder then issuing delete.  After 
> > expunge message still remains in inbox and customer folder.
> 
> >
> 
> >  # COPY EMAIL TO FOLDER
> 
> >  copyStatus = m.copy(emailid, 'CIRIMPORTED')
> 
> >  print 'id of message copied is: %s status: %s' % 
> > (emailid,copyStatus)
> 
> >
> 
> >  # SET THE MESSAGE TO HAVE '\Deleted' FLAG (EXPUNGE WILL COMPLETE 
> > DELETE PROCESS)
> 
> >  storeStatus = m.store(emailid,"+FLAGS", r'(\Deleted)')
> 
> >  print 'id of message stored is: %s status: %s %s' % 
> > (emailid,storeStatus[0],storeStatus[1])
> 
> >  #print '**'
> 
> >
> 
> >  #DELETES ANY EMAIL MARKED \Deleted
> 
> >  m.expunge()
> 
> >  m.close()
> 
> >  m.logout()
> 
> >
> 
> > Does anyone have any imaplib code the works with Gmail to move from inbox 
> > to another folder?
> 
> >
> 
> There's an example in docs which says:
> 
> 
> 
>  M.store(num, '+FLAGS', '\\Deleted')
> 
> 
> 
> You have:
> 
> 
> 
>  m.store(emailid,"+FLAGS", r'(\Deleted)')
> 
> 
> 
> Could it be that the flags should be r'\Deleted'?

I have tried it with the variations on the web of \\Deleted, r'\Deleted, and 
\Deleted.  The Delete works because I see in the status 'Deleted'.  However it 
does not remove from Inbox.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Missing something on exception handling in Python 3

2013-08-26 Thread Skip Montanaro
I have code in the pylockfile package that looks roughly like this
(apologies for the indentation - I'm growing to dislike Gmail for
typing code fragments):

try:
write_pid_to_lockfile(somefile)
except OSError as exc:
if conditions_i_can_handle:
   do_other_stuff...
else:
raise LockFailed("Failed to create %s" % self.path)

Thinking I would just get the final exception (not the one I caught
originally), I was surprised to see this output on my screen:

>>> lock.acquire()
Traceback (most recent call last):
  File "lockfile/pidlockfile.py", line 80, in acquire
write_pid_to_pidfile(self.path)
  File "lockfile/pidlockfile.py", line 163, in write_pid_to_pidfile
pidfile_fd = os.open(pidfile_path, open_flags, open_mode)
OSError: [Errno 13] Permission denied: '/tmp/skip/lock'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
  File "lockfile/pidlockfile.py", line 94, in acquire
raise LockFailed("failed to create %s" % self.path)
lockfile.LockFailed: failed to create /tmp/skip/lock

When I rung the same code with Python 2.7, I get the exception output
I anticipate:

>>> lock.acquire()
Traceback (most recent call last):
  File "", line 1, in 
  File "lockfile/pidlockfile.py", line 94, in acquire
raise LockFailed("failed to create %s" % self.path)
LockFailed: failed to create /tmp/skip/lock

It appears exception handling changed in Python 3.  How do I suppress
the lower level OSError?

Thx,

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


Re: Missing something on exception handling in Python 3

2013-08-26 Thread MRAB

On 27/08/2013 02:48, Skip Montanaro wrote:

I have code in the pylockfile package that looks roughly like this
(apologies for the indentation - I'm growing to dislike Gmail for
typing code fragments):

try:
 write_pid_to_lockfile(somefile)
except OSError as exc:
 if conditions_i_can_handle:
do_other_stuff...
 else:
 raise LockFailed("Failed to create %s" % self.path)

Thinking I would just get the final exception (not the one I caught
originally), I was surprised to see this output on my screen:


lock.acquire()

Traceback (most recent call last):
   File "lockfile/pidlockfile.py", line 80, in acquire
 write_pid_to_pidfile(self.path)
   File "lockfile/pidlockfile.py", line 163, in write_pid_to_pidfile
 pidfile_fd = os.open(pidfile_path, open_flags, open_mode)
OSError: [Errno 13] Permission denied: '/tmp/skip/lock'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   File "", line 1, in 
   File "lockfile/pidlockfile.py", line 94, in acquire
 raise LockFailed("failed to create %s" % self.path)
lockfile.LockFailed: failed to create /tmp/skip/lock

When I rung the same code with Python 2.7, I get the exception output
I anticipate:


lock.acquire()

Traceback (most recent call last):
   File "", line 1, in 
   File "lockfile/pidlockfile.py", line 94, in acquire
 raise LockFailed("failed to create %s" % self.path)
LockFailed: failed to create /tmp/skip/lock

It appears exception handling changed in Python 3.  How do I suppress
the lower level OSError?


Do this:

raise LockFailed("Failed to create %s" % self.path) from None

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


Re: Missing something on exception handling in Python 3

2013-08-26 Thread Skip Montanaro
> Do this:
>
> raise LockFailed("Failed to create %s" % self.path) from None

Thanks. Is there some construct which will work in 2.x and 3.x?

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


TypeError: 'int' object is not callable

2013-08-26 Thread autobotprime . 17
dear friends when i try to execute following lines

import time
a = time.daylight()
print(a)


result is
TypeError: 'int' object is not callable


why is this error and how can i solve this problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: 'int' object is not callable

2013-08-26 Thread Krishnan Shankar
Hi,

The problem is in the second line.

a = time.daylight()

The daylight is not a method in time module. It is clear here,
http://docs.python.org/2/library/time.html

Since it is not a method we cannot call it. It is just a integer variable .
It returns zero if DST timezone is not defined and returns non zero if
defined.

>>> import time
>>> a = time.daylight()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not callable
>>> a = time.daylight
>>> a
0
>>> type(time.daylight)


Regards,
Krishnan


On Tue, Aug 27, 2013 at 8:15 AM,  wrote:

> dear friends when i try to execute following lines
>
> import time
> a = time.daylight()
> print(a)
>
>
> result is
> TypeError: 'int' object is not callable
>
>
> why is this error and how can i solve this problem?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing something on exception handling in Python 3

2013-08-26 Thread Ethan Furman

On 08/26/2013 07:49 PM, Skip Montanaro wrote:

Do this:

 raise LockFailed("Failed to create %s" % self.path) from None


Thanks. Is there some construct which will work in 2.x and 3.x?


Something like this (untested):

exc = None
try:
write_pid_to_lockfile(somefile)
except OSError as exc:
exc = sys.exc_info()[0]   # not sure of index
if exc:
if conditions_i_can_handle:
do_other_stuff...
else:
raise LockFailed("Failed to create %s" % self.path)

Since you're raising outside the try...except block you won't see the chained 
exception in Python3.

--
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Phonon error: libv4l2: error getting pixformat: Invalid argument

2013-08-26 Thread tausciam
Here is my code. I'm just trying to play an mp3 that I've clicked in a PyQT 
listwidget:

@pyqtSlot()
def item_clicked(self):
row = self.listWidget.currentRow()
song = musiclist[row]
QCoreApplication.setApplicationName("Phonon")
output = Phonon.AudioOutput(Phonon.MusicCategory)
m_media = Phonon.MediaObject()
Phonon.createPath(m_media, output)
m_media.setCurrentSource(Phonon.MediaSource(song))
m_media.play() 

I'm running OpenSUSE Linux 12.3

Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing something on exception handling in Python 3

2013-08-26 Thread Skip Montanaro
I found this question/answer on Stack Overflow:

http://stackoverflow.com/questions/15123137

but after fiddling around with it, I can't find a solution that works
for Python 3.2 and 3.3, let alone 2.x.  In 3.2, exceptions have both
__cause__ and __context__ attributes.  I tried setting both to None
(in 3.2), but I still get the full double traceback:

>>> try: 1/0
... except ZeroDivisionError:
...exc = TypeError()
...exc.__context__ = None
...exc.__cause__ = None
...raise exc
...
Error in sys.excepthook:
IndexError: tuple index out of range

Original exception was:
Traceback (most recent call last):
  File "", line 1, in 
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 6, in 
TypeError

The sys.excepthook error is because I have a custom interactive
sys.excepthook, which is itself apparently broken in Python 3.2.

I've looked at PEP 409 and 415, but just get more confused.

*sigh*

Maybe I'll try again tomorrow when I've had a bit of sleep... and take
a closer look at Ethan's suggestion.

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


Re: How come StopIteration.__base__ is not BaseException?

2013-08-26 Thread Marco Buttu

On 08/27/2013 08:17 AM, Marco Buttu wrote:

But if I want to catch it specifically (except BaseIteration),



Sorry, except StopIteration...
--
Marco Buttu
--
http://mail.python.org/mailman/listinfo/python-list


Re: How come StopIteration.__base__ is not BaseException?

2013-08-26 Thread Marco Buttu

On 08/26/2013 10:10 PM, random...@fastmail.us wrote:


The reason KeyboardInterrupt and SystemExit inherit from BaseException
is because you often want them to escape (allowing the program to quit)
from code that would otherwise catch them (by catching Exception). On
the contrary, StopIteration is almost always used in a context that
catches it specifically.


But if I want to catch it specifically (except BaseIteration), why
doesn't it hinerit directly from BaseException? It's not an error and 
it's not a warning. I would like to see a piece of code in which it is
useful to catch it generically with a except Exception clause instead of 
an except StopIteration...

Regards
--
Marco
--
http://mail.python.org/mailman/listinfo/python-list