Re: What does "pip install" do?

2015-01-13 Thread Chris Angelico
On Tue, Jan 13, 2015 at 6:51 PM, Fabien  wrote:
> Thanks Chris. I should then rephrase my question to "what does python
> setup.pt do?" ;-). My point was also that I think that this information
> (mostly: what will change on my system or my virtual env when I install a
> python package?) could/should be provided in the mentioned resources:

You'd have to look at the individual packages' setup.py files, I guess.

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


Re: I must be missing something obvious in installing Python 3.4.2...

2015-01-13 Thread Tim Golden
On 13/01/2015 07:05, [email protected] wrote:
> On Monday, January 12, 2015 at 10:09:03 PM UTC-8, Tim Golden wrote:
>> On 12/01/2015 23:12, Andrew Koenig wrote:
>>> Fixed it!
>>>
>>> The aforementioned article is correct. I downloaded the RegDelNull
>>> program mentioned in the article
>>> (http://technet.microsoft.com/en-us/sysinternals/bb897448.aspx) and
>>> ran it on hkcr, hkcu, hklm, hku, and hkcc (short for
>>> HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS,
>>> and HKEY_CURRENT_CONFIG), respectively. It deleted a bunch of keys.
>>> Rerunning the program you posted earlier revealed no keys with
>>> embedded nulls in their names, and ensurepip now works.
>>>
>>> I have no idea how these keys got there. For all I know they are the
>>> result of malware.
>>>
>>> I think it would be worthwhile changing the Python code to detect
>>> nulls and perhaps issue a warning that directs people to this article
>>> or something like it.
>>>
>>
>> Thanks, yes. Unfortunate that no-one's actually reported this before as 
>> a bug -- as far as I'm aware. Would you be in a position to report this 
>> at bugs.python.org? If not, I'll do it when I get a chance.
>>
>> TJG
> 
> 
> 

(Sigh). Thanks -- and I'm even listed on the call. In my defence it was
logged while I was away over the summer and I did a bit of a bulk delete
when I came back.

Thanks

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


Re: Using a ChangeLog as a canonical source of package metadata

2015-01-13 Thread Steven D'Aprano
On Tue, 13 Jan 2015 00:09:04 -0800, wxjmfauth wrote:

> Le mardi 13 janvier 2015 08:00:06 UTC+1, Steven D'Aprano a écrit :
>> On Mon, 12 Jan 2015 05:24:00 -0800, wxjmfauth wrote:
>> 
>> > To tell you the truth, I'm unable to
>> > put your product to work.
>> 
>> 
>> If you follow the instructions in the README, and it still doesn't
>> work, that's a bug and I will be happy to fix it.
>> 
>> If you insist on doing things your own way, and breaking the package,
>> then I cannot help you.
>> 
>> 
> No, I do not claim, your package is buggy. I just wanted to toy with it
> without installing it in the XXX\pythonXX directory structure.


It is a pure Python package. Copy the package directory out of the tar 
ball and put it where Python can see it, and it will work.

If you need to read more about packages, start here:

https://docs.python.org/2/tutorial/modules.html#packages


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


Re: class-based class decorator

2015-01-13 Thread Albert-Jan Roskam




- Original Message -
> From: Jean-Michel Pichavant 
> To: Albert-Jan Roskam 
> Cc: Python 
> Sent: Monday, January 12, 2015 4:20 PM
> Subject: Re: class-based class decorator
> 
> - Original Message -
>>  From: "Albert-Jan Roskam" 
> 
>>  import functools
>>  import inspect
>>  import warnings
>> 
>>  warnings.simplefilter("always")
>> 
>>  class check_deprecated_args(object):
>> 
>>  def __init__(self, deprecated_params, msg=None):
>>  self.deprecated_params = deprecated_params
>>  self.msg = msg
>> 
>>  def __call__(self, func):
>>  @functools.wraps(func)
>>  def inner(*args, **kwargs):
>>  argspec = inspect.getargspec(func)
>>  default_signature = dict(zip(argspec.args[1:],
>>  argspec.defaults))
>>  callargs = inspect.getcallargs(func, *args, **kwargs)
>>  deprecated_calls = [(p, a) for p, a in callargs.items()
>>  if
>>   p in self.deprecated_params and
>>   a != default_signature[p]]
>>  for (param, arg) in deprecated_calls:
>>  msg = "you're using obsolete parameters in %s:
>>  [%s:%s]"
>>  msg = msg % (func.__name__, param, arg)
>>  msg = msg + " " + self.msg if self.msg else msg
>>  warnings.warn(msg, DeprecationWarning, stacklevel=2)
>>  return func(*args, **kwargs)
>>  functools.update_wrapper(inner, func)
>>  return inner
>> 
>>  if __name__ == "__main__":
>>  class Foo(object):
>> 
>>  @check_deprecated_args(["old", "older"], 
> "use 'brand_new'
>>  param instead")
>>  def __init__(self, old="old", older="ancient"):
>>  print "hello"
>> 
>>  @check_deprecated_args(deprecated_params=["old", 
> "older"])
>>  def bar(self, old="default"):
>>  print "world"
>> 
>>  f = Foo(old="old", older="dino era")
>>  f.bar("gnarly")
>> 
>>  help(f)  # now the signature is *args, **kwargs, which makes my
>>  Sphinx documentation less readable!
>> 
>>  Best wishes,
>>  Albert-Jan
> 
> I don't really understand how you successfuly manage positional parameters, 
> since the caller may not name them.
> I'm asking because if your intend to check only the keyword parameters, 
> there's a much simplier solution.
> 
> JM


Hi,

Can you give an example of where/how my code would fail? I do not intend to use 
*args and **kwargs, if that is what you mean. I am interested in hearing a 
simpler approach, especially if it would also solve the messed-up-signature 
problem that I mentioned.

Thank you!

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


How can i use a dictionnary

2015-01-13 Thread brice DORA
i consume a web service that return a element whose the type is "instance". but 
this element seem be a dictionary but when i want to use it like a dictionary, 
i got some errors. so this is the element and please someone can tell me how 
can i use it. tkanks in advance.


(tCountryInfo){
   sISOCode = "CI"
   sName = "Côte D'Ivoire (Ivory Coast)"
   sCapitalCity = "Yamoussoukro"
   sPhoneCode = "225"
   sContinentCode = "AF"
   sCurrencyISOCode = "XOF"
   sCountryFlag = "http://www.oorsprong.org/WebSamples.CountryInfo/Images/Côte 
D'Ivoire.jpg"
   Languages = 
  (ArrayOftLanguage){
 tLanguage[] = 
(tLanguage){
   sISOCode = "fr"
   sName = "French"
},
  }
 }
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 2.7, on windows7 64 bit development machine, inconsistent issue on similar machines

2015-01-13 Thread Jacob Kruger
Trying to run through all steps in data conversion app, and, up to last point, 
it's fine, but, if I try to handle direct execution of data structure, and data 
insertion scripts against a mySQL database, hosted locally here on same 
machine, running under wamp, then after code has completely finished executing 
everything, the command line just stops, and then I get the windows error 
dialogue pop up, telling me python.exe has stopped working.

If I run the same code on my other dev machine, which might just have a 
slightly simpler/cleaner combination of software, etc. installed on it, then it 
just runs straight through, and exits python interpreter instance, with no 
issues, and am just not sure how to try track down actual cause of this issue.

Here's part of the error dialogue's detailed information:
Problem signature:

Problem Event Name: APPCRASH

Application Name: python.exe

Application Version: 0.0.0.0

Application Timestamp: 4c303241

Fault Module Name: StackHash_0a9e

Fault Module Version: 0.0.0.0

Fault Module Timestamp: 

Exception Code: c005

Exception Offset: 028e1289

OS Version: 6.1.7601.2.1.0.256.1

Locale ID: 2057

Additional Information 1: 0a9e

Additional Information 2: 0a9e372d3b4ad19135b953a78882e789

Additional Information 3: 0a9e

Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

#---end of error info---



If I look for something similar via google, etc., I come across some mention of 
32-64 bit incompatibility, or something, but, not sure if relevant, although am 
working with 32 bit versions of python 2.7, and both of my dev machines are in 
fact 64 bit windows7 machines, but haven't had issues like this in past.



Also, if I exclude last part of code, which handles directly working with MySQL 
database, then all cooperates fine, but, am pretty sure am closing all relevant 
connections, cursors, etc. - here's the last function that am 
calling/executing, in case relevant - there is still some testing/manual 
debugging stuff in here, but anyway:

#---start code---

  def convertExport(self):
try:
  f_mysql = open("mysql.set", "rb")
  d_mysql = pickle.load(f_mysql)
  f_mysql.close()
  cn = None
  s_host = str(d_mysql["host"])
  s_user = str(d_mysql["user"])
  s_pass = str(d_mysql["password"])
  s_db = self.s_target_value
  cn = MySQLdb.connect(s_host, s_user, s_pass, s_db)
  if cn:
cn.autocommit = True
cur = cn.cursor()
i_struct = 0
i_data = 0
f = open(self.s_sql_struct_file, "rb")
s = f.read()
f.close()
l_struct = s.split(";")
f = open(self.s_sql_data_file, "rb")
s = f.read()
f.close()
l_data = unidecode(s).split(";")
l_struct_errors = []
l_data_errors = []
i_start_time = int(time.time())
s_status = "/{0} structs".format(str(len(l_struct)))
for I in range(len(l_struct)):
  try:
i_struct = I
if str(l_struct[I]).strip() != "": res = cur.execute(l_struct[I] + 
";")
print(l_struct[I])
  #except Warning as wrn:
  #  print("warning: " + str(wrn.args))
  except Exception as exc:
l_struct_errors.append([l_struct[I], copy.copy(exc)])
  finally:
pass
cn.commit()
time.sleep(2.0)
sNada = raw_input("hit enter to continue with data")
s_status = "/{0} data".format(str(len(l_data)))
for I in range(len(l_data)):
  try:
#self.SetStatusText(str(I) + s_status)
i_data = I
if str(l_data[I]).strip() != "": res = 
cur.execute(l_data[I][l_data[I].index("INSERT"):] + ";")
print(l_data[I][l_data[I].index("INSERT"):] + ";")
  except Exception as exc:
l_data_errors.append([l_data[I], copy.copy(exc)])
  finally:
pass
i_end_time = int(time.time())
s_time_taken = sTimeDiffFormat(i_start_time, i_end_time)
cn.commit()
cur.close()
cn.close()
print("cn and cur closed")
fPickle = open("testDataErrors.pickle", "wb")
pickle.dump(l_struct_errors, fPickle, 2)
pickle.dump(l_data_errors, fPickle, 2)
fPickle.close()
print("pickled")
print("MySQL Results - {0} structure queries, and {1} data queries 
completed - total of {2}".format(str(i_struct), str(i_data), s_time_taken))
print("MySQL Errors - {0} structure query errors, and {1} data query 
errors".format(str(len(l_struct_errors)), str(len(l_data_errors
print("Done!")
sys.exit()
  else:
print("Connection issue - There was a problem connecting to MySQL 
server")
sys.exit()
except Exception as exc:
  s_exc = str(exc.args)
  #lbc.DialogShow(title="errorMessage", message=s_exc)
  print(s_exc)
  exc_type, exc_obj, tb = sys.exc_info()
  print(str(exc_obj))
  print("line numbe

Re: class-based class decorator

2015-01-13 Thread Albert-Jan Roskam


On Tue, Jan 13, 2015 6:31 AM CET Ian Kelly wrote:

>On Jan 12, 2015 6:47 AM, "Albert-Jan Roskam"  wrote:
>> Thanks for your replies. I changed it into a regular decorator (not a class 
>> decorator). It would have been even nicer if I only needed to specify it 
>> once per class, but, well, in my case this hardly matters. The code below 
>> works as intended. One problem (not specific to the code): the decorator 
>> destroys the signature: it always becomes "*args, **kwargs"). This is 
>> annoying with help(), but what worries me most is that my Sphinx 
>> documentation is also affected. The information about the defaults gets lost 
>> (the parameters are decribed in the docstring, but not the defaults). That 
>> kind of sucks. Is there a builtin way around this (in other words: I am 
>> aware of this package: https://pypi.python.org/pypi/decorator). I am hoping 
>> to get the code working on Python 2.7 and 3.3 and up.
>
>As of (I think) 3.4 pydoc and the help() function will show you the
>signature of the wrapped function as long as you use functools.wraps.
>I don't know what the status is for Sphinx; all I can offer is this
>stackoverflow link.
>
>http://stackoverflow.com/questions/3687046/python-sphinx-autodoc-and-decorated-members

Thank you! Luckily, decorator.py is just one file, so I could easily include 
it. Version 3.4 is needed, because of a bug in an older version. Now I still 
need to find out how to create a git submodule to a hg repo, where the 
decorator package is. :-)

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


Re: Broken IF statement

2015-01-13 Thread Maxime S
2015-01-12 22:19 GMT+01:00 :
>
> https://bpaste.net/show/93be9e15634b <--- Line 19 through 22
>
> At all times, my program is assigning the object priority of 0, even if
one already exists in the database with a priority of 0 (it's supposed to
be assigning it a priority of 1 in those cases).
>
> I'm a non developer trying to fix a freelancer's code. Would anybody be
able to suggest changes to the IF logic that might be able to fix it,
assuming the statements in the code provided look flawed?
>
> Thanks...
> --
> https://mail.python.org/mailman/listinfo/python-list


This line:

obj, created = SocialAccount.objects.get_or_create(...)

suggest you are using Django. If it is the case you have to add obj.save()
after changing the priority to send the new value to the DB.

Best,

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


Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Terry Reedy

On 1/13/2015 1:13 AM, Chris Angelico wrote:

On Tue, Jan 13, 2015 at 4:32 PM, Steven D'Aprano  wrote:

Crashing the interpreter from
pure Python code is *absolutely not allowed*, so anything which would
allow that is forbidden.


Except when you willingly shoot yourself in the foot.

rosuav@sikorsky:~$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import sys
def f(): sys.setrecursionlimit(sys.getrecursionlimit()+1) or f()

...

f()

Segmentation fault
rosuav@sikorsky:~$ python3
Python 3.5.0a0 (default:1c51f1650c42+, Dec 29 2014, 02:29:06)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

import sys
def f(): sys.setrecursionlimit(sys.getrecursionlimit()+1) or f()

...

f()

Segmentation fault

But otherwise, yes. You shouldn't be able to segfault Python with Python code.


I would have expected an out-of-memory error.  If there is not already a 
crash issue on the tracker for this, you could add one.



--
Terry Jan Reedy

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


Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Chris Angelico
On Tue, Jan 13, 2015 at 9:49 PM, Terry Reedy  wrote:
> I would have expected an out-of-memory error.  If there is not already a
> crash issue on the tracker for this, you could add one.

It's a stack fault, and it's a documented possibility:

https://docs.python.org/2/library/sys.html#sys.setrecursionlimit
https://docs.python.org/3/library/sys.html#sys.setrecursionlimit

Tracker search brings up this as a definite hit, and some other maybes:
http://bugs.python.org/issue6356

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


Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Marko Rauhamaa
Terry Reedy :

> On 1/13/2015 1:13 AM, Chris Angelico wrote:
> def f(): sys.setrecursionlimit(sys.getrecursionlimit()+1) or f()
>> ...
> f()
>> Segmentation fault
>>
>> But otherwise, yes. You shouldn't be able to segfault Python with
>> Python code.
>
> I would have expected an out-of-memory error. If there is not already
> a crash issue on the tracker for this, you could add one.

Linux grants memory it doesn't have. The truth comes out as a
segmentation fault. Call it modern banking.

The code above, though, shouldn't consume memory since it is a simple
tail-recursive loop.


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


Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Chris Angelico
On Tue, Jan 13, 2015 at 10:00 PM, Marko Rauhamaa  wrote:
> Terry Reedy :
>
>> On 1/13/2015 1:13 AM, Chris Angelico wrote:
>> def f(): sys.setrecursionlimit(sys.getrecursionlimit()+1) or f()
>>> ...
>> f()
>>> Segmentation fault
>>>
>>> But otherwise, yes. You shouldn't be able to segfault Python with
>>> Python code.
>>
>> I would have expected an out-of-memory error. If there is not already
>> a crash issue on the tracker for this, you could add one.
>
> Linux grants memory it doesn't have. The truth comes out as a
> segmentation fault. Call it modern banking.

I'm not sure it's a Linux problem. The same thing happens on Windows,
only without the "Segmentation fault" line. The exact behaviour on
stack overflow would depend on the layout of memory... back when I
wrote real-mode single-segment programs in DOS, the standard layout
was PSP, then code, then data, then stack, so overusing the stack
would overwrite your static data (and then, if you're really bad, your
code as well... things got fun then). My best guess now would be that
there's an actual boundary to the stack, and trying to access beyond
that triggers an immediate error - "you're not allowed to use that
memory". Nothing to do with over-allocating memory.

> The code above, though, shouldn't consume memory since it is a simple
> tail-recursive loop.

Only if the interpreter can optimize it away. Bear in mind that it
doesn't _return_ the result of that expression, so it needs to take
whatever f() returns, discard it, and return None. But I could have
defeated that, if I'd wanted to, by coding it to reduce the recursion
limit again after the call - it can't optimize away a non-tail-call.
Point is, if you take away the recursion limit, you _can_ crash
CPython. Likewise if you fiddle around with ctypes:

$ python3
Python 3.5.0a0 (default:1c51f1650c42+, Dec 29 2014, 02:29:06)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.cast(id(1), ctypes.POINTER(ctypes.c_int))[6]=2
>>> 1
Segmentation fault

Not a bug. just a gun that you can shoot yourself in the foot with.

(Code nicked from
http://www.reddit.com/r/Python/comments/2441cv/can_you_change_the_value_of_1/
- from a comment saying "changing 1 this way just destroys
everything". Yep, it does, and pretty quckly too.)

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


Re: Python 3 regex woes (parsing ISC DHCPD config)

2015-01-13 Thread Thomas 'PointedEars' Lahn
Jason Bailey wrote:

> My script first reads the DHCPD configuration file into memory -
> variable "filebody". It then utilizes the re module to find the
> configuration details for the wanted "shared network".
> 
> The config file might look something like this:
> 
> ##
> 
> shared-network My-Network-MOHE {
>subnet 192.168.0.0 netmask 255.255.248.0 {
>  option routers 192.168.0.1;
>  option tftp-server-name "192.168.90.12";
>  pool {
>deny dynamic bootp clients;
>range 192.168.0.20 192.168.7.254;
>  }
>}
> }
> 
> shared-network My-Network-CDCO {
>subnet 192.168.8.0 netmask 255.255.248.0 {
>  option routers 10.101.8.1;
>  option tftp-server-name "192.168.90.12";
>  pool {
>deny dynamic bootp clients;
>range 192.168.8.20 192.168.15.254;
>  }
>}
> }
> 
> shared-network My-Network-FECO {
>subnet 192.168.16.0 netmask 255.255.248.0 {
>  option routers 192.168.16.1;
>  option tftp-server-name "192.168.90.12";
>  pool {
>deny dynamic bootp clients;
>range 192.168.16.20 192.168.23.254;
>  }
>}
> }
> 
> ##
> 
> Suppose I'm trying to grab the shared network called "My-Network-FECO"
> from the above config file stored in the variable 'filebody'.
> 
> First I have my variable 'shared_network' which contains the string
> "My-Network-FECO".
> 
> I compile my regex:
> m = re.compile(r"^(shared\-network (" + re.escape(shared_network) + r")
> \{((\n|.|\r\n)*?)(^\}))", re.MULTILINE|re.UNICODE)

This code does not run as posted.  Applying Occam’s Razor, I think you meant 
to post

m = re.compile(r"^(shared\-network ("
  + re.escape(shared_network)
  + r") \{((\n|.|\r\n)*?)(^\}))", re.MULTILINE|re.UNICODE)

(If you post long lines, know where your automatic word wrap happens.)

> I search for regex matches in my config file:
> m.search(filebody)

I find using the identifier “m” for the expression very strange.  Usually I 
reserve “m” to hold the *matches* for an expression on a string.
Consider “r” or “rx” or something else instead of “m” for the expression.

> Unfortunately, I get no matches. From output on the command line, I can
> see that Python is adding extra backslashes to my re.compile string. I
> have added the raw 'r' in front of the strings to prevent it, but to no
> avail.

Python is adding the extra backslashes because you used “r”.  Note that the 
console-printed string representations of strings do not have an “r” in 
front of them.  What you see is what you would have needed to write for 
equivalent code if you had not used “r”.  (Different from some other 
languages, Python does not distinguish between single-quoted and double-
quoted strings with regard to parsing.  Hence the r'…' feature, the triple-
quoted string, and the .format() method.)

You get no matches because you have escaped the HYPHEN-MINUSes (“-”).  You 
never need to escape those characters, in fact you must not do that here 
because r'\-' is not an (unnecessarily) escaped HYPHEN-MINUS, it is a 
literal backslash followed by a HYPHEN-MINUS, a character sequence that does 
not occur in your string.  Outside of a character class you do not need to 
do that, and in a character class you can put it as first or last character 
instead (“[-…]” or “[…-]”).

You have escaped the first HYPHEN-MINUS; re.escape() has escaped the other 
two for you:

| >>> re.escape('-')
| '\\-'

I presume this behavior is because of character classes, and the idea that 
the return value should work at any position in a character class.

ISTM that you cannot use re.escape() here, and you must escape special 
characters yourself (using re.sub()), should they be possible in the file.

I do not see a reason for making the entire expression a group (but for 
making the network name a group).  

You should refrain from parsing non-regular languages with a *single* 
regular expression (multiple expressions or expressions with alternation in 
a loop are usually fine; this can be used for building efficient parsers), 
even though Python’s regular expressions, which are not an exception there, 
are not exactly “regular” in the theoretical computer science sense.  See 
the Chomsky hierarchy and Jeffrey E. F. Friedl’s insightful textbook 
“Mastering Regular Expressions”.

It is possible that there is a Python module for parsing ISC dhcpd 
configuration files already.  If so, you should use that instead.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-13 Thread stephen . boulet
I found a solution that I'm happy with.

from datetime import datetime
from easygui_qt import *

datestring = get_date()
mydate = datetime.strptime(datestring, '%b %d %Y')

On Saturday, January 10, 2015 at 1:02:30 AM UTC, André Roberge wrote:
> On Friday, 9 January 2015 19:09:15 UTC-4, [email protected]  wrote:
> > On Wednesday, December 31, 2014 at 4:24:50 PM UTC-6, André Roberge wrote:
> > > EasyGUI_Qt version 0.9 has been released.  This is the first announcement 
> > > about EasyGUI_Qt on this list.
> > > 
> > > Like the original EasyGUI (which used Tkinter), 
> > > EasyGUI_Qt seeks to provide simple GUI widgets
> > > that can be called in a procedural program. 
> > > 
> > > EasyGUI_Qt is NOT event-driven: all GUI interactions are invoked by 
> > > simple function calls.
> > > 
> > > The archetype is get_string(message)
> > > which pops a box whose purpose is exactly the same as Python's 
> > > input(prompt),
> > > that is, present the user with a question/prompt, have the user enter an
> > > answer, and return the provided answer as a string.  Thus
> > > easygui_qt.get_string() can be used as a drop-in replacement for
> > > input().
> > > 
> > > Similarly, instead of using a print() function to display a message,
> > > show_message() is used which pops a message window.
> > > 
> > > EasyGUI_Qt requires PyQt4 and is really targeted for Python 3.3+ - 
> > > although it can work (possibly with some unicode problems ...) using 
> > > Python 2.7.
> > > 
> > > More information can be found at 
> > > http://easygui-qt.readthedocs.org/en/latest/index.html
> > > 
> > > Feedback is most welcome, including reporting bugs to 
> > > https://github.com/aroberge/easygui_qt/issues
> > > 
> > > Happy 2015 everyone,
> > > 
> > > André Roberge
> > 
> > Very nice, thanks.
> > 
> > One issue is the format returned for the calendar selection. For today, the 
> > string returned is "Fri Jan 9 2015". My script needs to convert the date to 
> > a datetime.date, and having the month returned as a string instead of an 
> > integer makes this harder.
> 
> Would today's date be represented as the string "09.01.2015" useful to you? 
> (I found out how to do this.)  If so, I could perhaps add an argument like 
> numeric_format = True.
> 
> André
-- 
https://mail.python.org/mailman/listinfo/python-list


Help understanding list operatoins inside functions in python 3

2015-01-13 Thread stephen . boulet
I'm a bit confused why in the second case x is not [1,2,3]:

x = []

def y():
x.append(1)

def z():
x = [1,2,3]

y()
print(x)
z()
print(x)

Output:
[1]
[1]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 regex?

2015-01-13 Thread alister
On Tue, 13 Jan 2015 04:36:38 +, Steven D'Aprano wrote:

> On Mon, 12 Jan 2015 19:48:18 +, Ian wrote:
> 
>> My recommendation would be to write a recursive decent parser for your
>> files.
>> 
>> That way will be easier to write,
> 
> I know that writing parsers is a solved problem in computer science, and
> that doing so is allegedly one of the more trivial things computer
> scientists are supposed to be able to do, but the learning curve to
> write parsers is if anything even higher than the learning curve to
> write a regex.
> 
> I wish that Python made it as easy to use EBNF to write a parser as it
> makes to use a regex :-(
> 
> http://en.wikipedia.org/wiki/Extended_Backus–Naur_Form



I would not say that writing parsers is a solved problem.
there may be solutions for a number of specific cases but many cases 
still cause difficulty, as an example I do not think there is a 100% 
complete parser for English (even native English speakers don't always 
get it)

-- 
Keep the number of passes in a compiler to a minimum.
-- D. Gries
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help understanding list operatoins inside functions in python 3

2015-01-13 Thread Joel Goldstick
On Tue, Jan 13, 2015 at 7:51 AM,  wrote:

> I'm a bit confused why in the second case x is not [1,2,3]:
>
> x = []
>
> def y():
> x.append(1)
>
> def z():
> x = [1,2,3]
>
> y()
> print(x)
> z()
> print(x)
>
> Output:
> [1]
> [1]
>

x in the outer scope is not x in the z() scope

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



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


Re: Help understanding list operatoins inside functions in python 3

2015-01-13 Thread Laurent Pointal
Hello,

[email protected] wrote:

> I'm a bit confused why in the second case x is not [1,2,3]:
> 
> x = []
> 
> def y():
> x.append(1)
> 
> def z():
> x = [1,2,3]

Here x is a local, so global x is not modified.
If you want to modify gobal x, write:
def z():
global x
x = [1,2,3]

You can read the Python FAQ about global/local rules:

https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python

Or Dive Into Python

http://www.diveintopython.net/html_processing/locals_and_globals.html

(and for your problem, its the same with Python2 and Python3)

Or…

A+
Laurent.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 regex?

2015-01-13 Thread Jussi Piitulainen
alister  writes:

> On Tue, 13 Jan 2015 04:36:38 +, Steven D'Aprano wrote:
> 
> > On Mon, 12 Jan 2015 19:48:18 +, Ian wrote:
> > 
> >> My recommendation would be to write a recursive decent parser for
> >> your files.
> >> 
> >> That way will be easier to write,
> > 
> > I know that writing parsers is a solved problem in computer
> > science, and that doing so is allegedly one of the more trivial
> > things computer scientists are supposed to be able to do, but the
> > learning curve to write parsers is if anything even higher than
> > the learning curve to write a regex.
> > 
> > I wish that Python made it as easy to use EBNF to write a parser as it
> > makes to use a regex :-(
> > 
> > http://en.wikipedia.org/wiki/Extended_Backus–Naur_Form
> 
> I would not say that writing parsers is a solved problem.  there may
> be solutions for a number of specific cases but many cases still
> cause difficulty, as an example I do not think there is a 100%
> complete parser for English (even native English speakers don't
> always get it)

There is no complete characterization of English as a set of character
strings, nor will there ever be. Linguists have a slogan for this: All
Grammars Leak. (They used to write formal grammars to characterize
"all and only the well-formed sentences" of a language, or to capture
"necessary and sufficient conditions", and those grammars turned out
to both "over-generate" and "under-generate".)

Ambiguity doesn't help. In practice, it's not enough to find a parse.
One wants a contextually appropriate parse. Sometimes this requires
genuine understanding and knowledge. Also in practice, one may not be
in the business of rejecting ill-formed sentences: one wants to make
partial sense of even those. So, no, never 100 percent complete or 100
percent correct :)

The solved problem is the unambiguous parsing of formal languages that
are defined by a formal grammar to begin with, like the configuration
file format at hand.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help understanding list operatoins inside functions in python 3

2015-01-13 Thread mortoxa


On 01/13/15 23:51, [email protected] wrote:

I'm a bit confused why in the second case x is not [1,2,3]:

x = []

def y():
 x.append(1)

def z():
 x = [1,2,3]

y()
print(x)
z()
print(x)

Output:
[1]
[1]


In your y() function, as you are appending data, the list must already 
exist. So the global list x is used


In your z() function, you are creating a local list x which only exists 
as long as you are in the function.
Anything you do to that list has no effect on the global list x. That is 
why the list does not change.


If you specifically wanted to change the global list x, you could do this:

def z():
global x
x = [1, 2, 3]

Output:
[1]
[1, 2, 3]

Or better

def z():
x = [1, 2, 3]
return x

y()
print(x)
x = z()
print(x)

Output:
[1]
[1, 2, 3]
-- 
https://mail.python.org/mailman/listinfo/python-list


what would be the regular expression for null byte present in a string

2015-01-13 Thread Shambhu Rajak
I have a string that I get as an output of a command as:
'\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x0010232ae8944a\x02\x00\x00\x00\x00\x00\x00\x00\n'

I want to fetch '10232ae8944a' from the above string.

I want to find a re pattern that could replace all the \x01..\x0z to be replace 
by empty string '',  so that I can get the desired portion of string

Can anyone help me with a working regex for it.

Thanks,
Shambhu



PLEASE NOTE: The information contained in this electronic mail message is 
intended only for the use of the designated recipient(s) named above. If the 
reader of this message is not the intended recipient, you are hereby notified 
that you have received this message in error and that any review, 
dissemination, distribution, or copying of this message is strictly prohibited. 
If you have received this communication in error, please notify the sender by 
telephone or e-mail (as shown above) immediately and destroy any and all copies 
of this message in your possession (whether hard copies or electronically 
stored copies).

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


Re: Broken IF statement

2015-01-13 Thread joboppsgpp
On Monday, January 12, 2015 at 4:55:43 PM UTC-5, [email protected] wrote:
> Thanks Chris. This definitely helps. I will test it and see what happens. In 
> terms of the previous code, what it was intended to do wasn't actually 
> happening.

Thanks Chris. Your change worked.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Broken IF statement

2015-01-13 Thread joboppsgpp
On Tuesday, January 13, 2015 at 4:57:50 AM UTC-5, Maxime S wrote:
> 2015-01-12 22:19 GMT+01:00 :
> >
> > https://bpaste.net/show/93be9e15634b <--- Line 19 through 22
> >
> > At all times, my program is assigning the object priority of 0, even if one 
> > already exists in the database with a priority of 0 (it's supposed to be 
> > assigning it a priority of 1 in those cases).
> >
> > I'm a non developer trying to fix a freelancer's code. Would anybody be 
> > able to suggest changes to the IF logic that might be able to fix it, 
> > assuming the statements in the code provided look flawed?
> >
> > Thanks...
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> 
> This line:
> 
> obj, created = SocialAccount.objects.get_or_create(...)
> 
> suggest you are using Django. If it is the case you have to add obj.save() 
> after changing the priority to send the new value to the DB.
> 
> Best,
> 
> Maxime

Thanks Maxime. I'll try that as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what would be the regular expression for null byte present in a string

2015-01-13 Thread Peter Otten
Shambhu Rajak wrote:

> I have a string that I get as an output of a command as:
> 
'\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x0010232ae8944a\x02\x00\x00\x00\x00\x00\x00\x00\n'
> 
> I want to fetch '10232ae8944a' from the above string.
> 
> I want to find a re pattern that could replace all the \x01..\x0z to be
> replace by empty string '',  so that I can get the desired portion of
> string
> 
> Can anyone help me with a working regex for it.

I think you want the str.tranlate() method rather than a regex. 

Assuming you are using Python 2:

>>> delenda = "".join(map(chr, range(32)))
>>> identity = "".join(map(chr, range(256)))
>>> 
'\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x0010232ae8944a\x02\x00\x00\x00\x00\x00\x00\x00\n'.translate(identity,
 
delenda)
'10232ae8944a'

With Python3:

>>> mapping = dict.fromkeys(range(32))
>>> 
'\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x0010232ae8944a\x02\x00\x00\x00\x00\x00\x00\x00\n'.translate(mapping)
'10232ae8944a'


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


Re: How can i use a dictionnary

2015-01-13 Thread Novocastrian_Nomad
On Tuesday, January 13, 2015 at 2:03:30 AM UTC-7, brice DORA wrote:
> i consume a web service that return a element whose the type is "instance". 
> but this element seem be a dictionary but when i want to use it like a 
> dictionary, i got some errors. so this is the element and please someone can 
> tell me how can i use it. tkanks in advance.
> 
> 
> (tCountryInfo){
>sISOCode = "CI"
>sName = "Côte D'Ivoire (Ivory Coast)"
>sCapitalCity = "Yamoussoukro"
>sPhoneCode = "225"
>sContinentCode = "AF"
>sCurrencyISOCode = "XOF"
>sCountryFlag = 
> "http://www.oorsprong.org/WebSamples.CountryInfo/Images/Côte D'Ivoire.jpg"
>Languages = 
>   (ArrayOftLanguage){
>  tLanguage[] = 
> (tLanguage){
>sISOCode = "fr"
>sName = "French"
> },
>   }
>  }

This data is not a Python dictionary, nor is it a JSON object.  You will 
probably need to code your own conversion function to make it a Python 
dictionary.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can i use a dictionnary

2015-01-13 Thread random832
On Tue, Jan 13, 2015, at 04:03, brice DORA wrote:
> i consume a web service that return a element whose the type is
> "instance". but this element seem be a dictionary but when i want to use
> it like a dictionary, i got some errors. so this is the element and
> please someone can tell me how can i use it. tkanks in advance.

Do you have any more information about this web service, so that you can
find a formal specification (or at least name) of the output format, or
maybe a way to make it return XML or JSON instead?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 regex?

2015-01-13 Thread Rick Johnson
On Monday, January 12, 2015 at 11:34:57 PM UTC-6, Mark Lawrence wrote:
> You snipped the bit that says [normal cobblers snipped].

Oh my, where are my *manners* today? Tell you what, next time when
your sneaking up behind me with a knife in hand, do be a
friend and tap me on the shoulder first, so i can take the
knife and stab *myself* in the back!

Your pal, Rick.
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Python Meeting Düsseldorf - 20.01.2014

2015-01-13 Thread eGenix Team: M.-A. Lemburg
[This announcement is in German since it targets a local user group
 meeting in Düsseldorf, Germany]


ANKÜNDIGUNG

 Python Meeting Düsseldorf

 http://pyddf.de/

   Ein Treffen von Python Enthusiasten und Interessierten
in ungezwungener Atmosphäre.

  Dienstag, 20.01.2014, 18:00 Uhr
  Raum 1, 2.OG im Bürgerhaus Stadtteilzentrum Bilk
Düsseldorfer Arcaden, Bachstr. 145, 40217 Düsseldorf

Diese Nachricht ist auch online verfügbar:
http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2015-01-20


NEUIGKEITEN

 * Bereits angemeldete Vorträge:

   Dr. Klaus Bremer
   "Class-based Views in Django"
   "Evolutionssimulation mit genetischen Algorithmen"

   Detlef Lannert
   "Ansible-Erfahrungsbericht"

   Weitere Vorträge können gerne noch angemeldet werden: [email protected]

 * Startzeit und Ort:

   Wir treffen uns um 18:00 Uhr im Bürgerhaus in den Düsseldorfer
   Arcaden.

   Das Bürgerhaus teilt sich den Eingang mit dem Schwimmbad
   und befindet sich an der Seite der Tiefgarageneinfahrt der
   Düsseldorfer Arcaden.

   Über dem Eingang steht ein großes “Schwimm’'in Bilk”
   Logo. Hinter der Tür direkt links zu den zwei Aufzügen,
   dann in den 2. Stock hochfahren. Der Eingang zum Raum 1
   liegt direkt links, wenn man aus dem Aufzug kommt.

   Google Street View: http://bit.ly/11sCfiw


EINLEITUNG

Das Python Meeting Düsseldorf ist eine regelmäßige Veranstaltung in
Düsseldorf, die sich an Python Begeisterte aus der Region wendet:

 * http://pyddf.de/

Einen guten Überblick über die Vorträge bietet unser YouTube-Kanal,
auf dem wir die Vorträge nach den Meetings veröffentlichen:

 * http://www.youtube.com/pyddf/

Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld,
in Zusammenarbeit mit Clark Consulting & Research, Düsseldorf:

 * http://www.egenix.com/
 * http://www.clark-consulting.eu/


PROGRAMM

Das Python Meeting Düsseldorf nutzt eine Mischung aus Open Space
und Lightning Talks, wobei die Gewitter bei uns auch schon mal
20 Minuten dauern können ;-).

Lightning Talks können vorher angemeldet werden, oder auch
spontan während des Treffens eingebracht werden. Ein Beamer mit
XGA Auflösung steht zur Verfügung. Folien bitte als PDF auf USB
Stick mitbringen.

Lightning Talk Anmeldung bitte formlos per EMail an [email protected]


KOSTENBETEILIGUNG

Das Python Meeting Düsseldorf wird von Python Nutzern für Python
Nutzer veranstaltet. Um die Kosten zumindest teilweise zu
refinanzieren, bitten wir die Teilnehmer um einen Beitrag
in Höhe von EUR 10,00 inkl. 19% Mwst, Schüler und Studenten
zahlen EUR 5,00 inkl. 19% Mwst.

Wir möchten alle Teilnehmer bitten, den Betrag in bar mitzubringen.


ANMELDUNG

Da wir nur für ca. 20 Personen Sitzplätze haben, möchten wir
bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung
eingegangen. Es erleichtert uns allerdings die Planung.

Meeting Anmeldung bitte formlos per EMail an [email protected]


WEITERE INFORMATIONEN

Weitere Informationen finden Sie auf der Webseite des Meetings:

http://pyddf.de/

Mit freundlichen Grüßen,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 13 2015)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> mxODBC Plone/Zope 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. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 regex woes (parsing ISC DHCPD config)

2015-01-13 Thread Thomas 'PointedEars' Lahn
Thomas 'PointedEars' Lahn wrote:

> Jason Bailey wrote:
>> shared-network My-Network-MOHE {
>>[…] {
>>
>> I compile my regex:
>> m = re.compile(r"^(shared\-network (" + re.escape(shared_network) + r")
>> \{((\n|.|\r\n)*?)(^\}))", re.MULTILINE|re.UNICODE)
> 
> This code does not run as posted.  Applying Occam’s Razor, I think you
> meant to post
> 
> m = re.compile(r"^(shared\-network ("
>   + re.escape(shared_network)
>   + r") \{((\n|.|\r\n)*?)(^\}))", re.MULTILINE|re.UNICODE)
> 
> […]
> You get no matches because you have escaped the HYPHEN-MINUSes (“-”).  You
> never need to escape those characters, in fact you must not do that here
> because r'\-' is not an (unnecessarily) escaped HYPHEN-MINUS, it is a
> literal backslash followed by a HYPHEN-MINUS, a character sequence that
> does not occur in your string.  Outside of a character class you do not
> need to do that, and in a character class you can put it as first or last
> character instead (“[-…]” or “[…-]”).
> 
> You have escaped the first HYPHEN-MINUS; re.escape() has escaped the other
> two for you:
> 
> | >>> re.escape('-')
> | '\\-'
> 
> I presume this behavior is because of character classes, and the idea that
> the return value should work at any position in a character class.

It would appear that while my answer is not entirely wrong, the first 
sentence of that section is.  You may escape the HYPHEN-MINUS there, and may 
use re.escape(); it has no effect on the expression because of what I said 
following that sentence.  One must consider that the string is first parsed 
by Python’s string parser and then by Python’s re parser.

So I have presently no specific idea why you get no matches, however

  r'\{((\n|.|\r\n)*?)(^\}'

is not a proper way to match matching braces and everything in-between.

To begin with, the proper expression to match any newline is r'(\r?\n|\r)' 
because the first matching alternative in an alternation, not the longest 
one, wins.  But if you specify re.DOTALL, you can simply use “.” for any 
character (including any newline combination).
 
> […]
> You should refrain from parsing non-regular languages with a *single*
> regular expression (multiple expressions or expressions with alternation
> in a loop are usually fine; this can be used for building efficient
> parsers), even though Python’s regular expressions, which are not an
> exception there,
> are not exactly “regular” in the theoretical computer science sense.  See
> the Chomsky hierarchy and Jeffrey E. F. Friedl’s insightful textbook
> “Mastering Regular Expressions”.

And for matching matching braces (sic!) with regular expressions, you need a 
recursive one (which is another extension of regular expressions as they are 
discussed in CS).  Or a parser in the first place.  Otherwise you match too 
much with greedy matching

  { { } } { { } }
  ^-^

or too little with non-greedy matching

  { { } } { { } }
  ^---^

CS regular expressions can be used to describe *regular* languages (Chomsky-
type 3).  Bracket languages are, in general, not regular (see “pumping lemma 
for regular languages”), so for them you need an PDA¹-like extension of CS 
regular expressions (the aforementioned recursive ones), or a PDA 
implementation in the first place.  Such a PDA implementation is part of a 
parser.


¹  
-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


how can I create a class and decode/encode as json?

2015-01-13 Thread robertchen117
I want to send Message to rabbitmq and receive from rabbitmq, message format is 
below. 

how can I create a class and decode/encode as json? 

{
   "message":{
  "dateCreated": "1417713299",
  "sourceApplication": "ID",
"destinationApplication": "Name",
  "messageUUID": "sdafdasdfas",
  "response-type":"queue",
  "response-type-details":"queue-name",
  "messageType":"request",
  "operations":[
 {
"sequence":0,
"operation":"add",
"version":1,
"data-type":"json",
"data-schema":"a.json",
"data-encoding":"base64",
"data-encryption":"BLOWFISH",
"data-encryption-keyname":"psk-name",
"data":""
 },
 {
"sequence":1,
"operation":"otherOperation",
"version":2.1,
"response-type":"topic",
"response-type-details":"topic-name",
"data-type":"XML",
"data-schema":"ddd.xsd",
"data-encoding":"string",
"data-encryption":"NONE",
"data":""
 }
  ]
   }
}

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


Re: class-based class decorator

2015-01-13 Thread Jean-Michel Pichavant
- Original Message -
> From: "Albert-Jan Roskam" 
> > From: Jean-Michel Pichavant 
> > I don't really understand how you successfuly manage positional
> > parameters,
> > since the caller may not name them.
> > I'm asking because if your intend to check only the keyword
> > parameters,
> > there's a much simplier solution.
> > 
> > JM
> 
> 
> Hi,
> 
> Can you give an example of where/how my code would fail? I do not
> intend to use *args and **kwargs, if that is what you mean. I am
> interested in hearing a simpler approach, especially if it would
> also solve the messed-up-signature problem that I mentioned.
> 
> Thank you!
> 
> Albert-Jan
> 

In the example you've given you've deprecated only keyword arguments. So I was 
wondering...

would the following *untested* code work ? :

def check_deprecated_args(deprecated):
  def decorator(func):
def inner(*args, **kwargs):
  for p in deprecated:
if p in kwargs:
  print '%s is deprecated' % p
  return func(*args, **kwargs)
return inner
  return decorator

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Performance in exec environnements

2015-01-13 Thread Jean-Baptiste Braun
Hi,

I'm working on auto-generated python code with the exec function. I've done
some performance benches :

% python -m timeit '1 + 1'
1000 loops, best of 3: 0.0229 usec per loop

% python -m timeit "exec('1 + 1')"
10 loops, best of 3: 11.6 usec per loop

-> Maybe creating an exec environnement (I don't know how it works) takes
time. But :

% python -m timeit "1 + 1; 1 + 1"
1000 loops, best of 3: 0.042 usec per loop

% python -m timeit "exec('1 + 1; 1 + 1')"
10 loops, best of 3: 15.7 usec per loop

-> As if executing one more 1 + 1 would take 4 more seconds (10
iterations) in an exec environnement.

Am I missing something or should I expect that result ? What does using
exec imply that causes such a difference ?

Jean-Baptiste Braun
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Track down SIGABRT

2015-01-13 Thread Israel Brewster
On Jan 12, 2015, at 5:51 PM, Jason Friedman  wrote:

>> I have a long-running python/CherryPy Web App server process that I am
>> running on Mac OS X 10.8.5. Python 2.7.2 running in 32-bit mode (for now, I
>> have the code in place to change over to 64 bit, but need to schedule the
>> downtime to do it). On the 6th of this month, during normal operation from
>> what I can tell, and after around 33 days of trouble-free uptime, the python
>> process crashed with a SIGABRT. I restarted the process, and everything
>> looked good again until yesterday, when it again crashed with a SIGABRT.
> 
> Can you monitor disk and memory on the host?  Perhaps it is climbing
> towards an unacceptable value right before crashing.

Good thought. I'm pretty sure that the system monitor still showed a couple of 
gigs free memory before the last crash, but the process could still be using 
unacceptable amounts of resources

> 
> Do you have the option of stopping and starting your process every
> night or every week?

Yes, that's an option, and as a work-around I'll consider it. Of course, I'd 
much rather not have the thing crash in the first place :-)

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

---
Israel Brewster
Systems Analyst II
Ravn Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
---

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


Re: Track down SIGABRT

2015-01-13 Thread Israel Brewster
On Jan 13, 2015, at 6:27 AM, William Ray Wing  wrote:

> 
>> On Jan 9, 2015, at 12:40 PM, Israel Brewster  wrote:
>> 
>> I have a long-running python/CherryPy Web App server process that I am 
>> running on Mac OS X 10.8.5. Python 2.7.2 running in 32-bit mode (for now, I 
>> have the code in place to change over to 64 bit, but need to schedule the 
>> downtime to do it). On the 6th of this month, during normal operation from 
>> what I can tell, and after around 33 days of trouble-free uptime, the python 
>> process crashed with a SIGABRT. I restarted the process, and everything 
>> looked good again until yesterday, when it again crashed with a SIGABRT. The 
>> crash dump the system gave me doesn't tell me much, other than that it looks 
>> like python is calling some C function when it crashes. I've attached the 
>> crash report, in case it can mean something more to someone else.
>> 
>> Can anyone give me some hints as to how to track down the cause of this 
>> crash? It's especially problematic since I can't mess with the live server 
>> for testing, and it is quite a while between crashes, making it difficult, 
>> if not impossible, to reproduce in testing. Thanks.
>> ---
>> Israel Brewster
>> Systems Analyst II
>> Ravn Alaska
>> 5245 Airport Industrial Rd
>> Fairbanks, AK 99709
>> (907) 450-7293
>> ---
> 
> 
> Can you run the application in an IDE?

Yes - I run it through Wing during development. I don't think that would be 
such a good option for my production machine, however. If it gets really bad 
I'll consider it though - that should at least tell me where it is crashing.

> 
> -Bill

---
Israel Brewster
Systems Analyst II
Ravn Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
---

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


Re: Python 3 regex?

2015-01-13 Thread Rick Johnson
On Tuesday, January 13, 2015 at 12:39:55 AM UTC-6, Steven D'Aprano wrote:
> On Mon, 12 Jan 2015 15:47:08 -0800, Rick Johnson wrote:
> [...]
> > [...]
> > 
> > #Ironic Twist (Reformatted)#
> > 
> > # Some diabetics, when confronted with hunger, think "I#
> > # know, I'll eat a box of sugar cookies." -- now they have #
> > # # # two problems!'   #
> > 
>
> Not the best of analogies, since there are two forms of
> diabetes. Those with Type 2 diabetes can best manage their
> illness by avoiding sugar cookies. Those with Type 1
> should keep a box of sugar cookies (well, perhaps glucose
> lollies are more appropriate) on hand for emergencies.

You seem to misunderstand the basic distinction between
type1 and type2 diabetes, it's not a mere dichotomy between
hyperglycemia and hypoglycemia that defines a diabetes
diagnosis, NO, Type1 can be simplified as "insulin
deficiency" and Type2 as "insulin resistance" -- with both
resulting in the inability of glucose (aka: fuel) to nourish
the cells.

YOUR ASSESSMENT OF MY ANALOGY IS JUST AS "WEAK".

Both my and Jamie's analogy present an example of the "cruel
irony". The only *DIFFERENCE* is that mine utilizes a
subject matter which requires less study to understand.

One can learn enough about diabetes to draw his own factual
conclusions of my statement from a simple Google search,
however, for regexps, a neophyte would need days, weeks, or
even months of serious study to drawn sensible conclusions
of merit.

> In any case, most people with diabetes (or at least those
> who are still alive) are reasonably good at managing their
> illness and wouldn't make the choice you suggest. You have
> missed the point that people who misuse regexes are common
> in programming circles, while diabetics who eat a box of
> sugar cookies instead of a meal are rare.

I believe you could find many diabetics who've eaten poorly
and suffered from the result -- even died! I'm not missing
the point, you are! 

HECK, *I'M* THE ONE WHO *DEFINED* THE "POINT".

> To take your analogy to an extreme:
>
>   Some people, when faced with a problem, say "I know, I'll cut
>   my arm off with a pocketknife!" Now they have two problems.
>
> This is not insightful or useful. Except in the most
> specialized and extreme circumstances, such as being
> trapped in the wilderness with a boulder on your arm,
> nobody would consider this to be good advice.

I'm not giving *advice*, i'm merely drawing parallels. I
think your repeated failures to understand me are are a
result of your superficiality. When reading my posts, you
need to learn to: "read between the lines". Many of the
writings i author are implicit philosophical statements,
musings, and/or explorations. For me, everything has deeper
meanings, just begging to be *plundered*!

> But using regexes to validate email addresses or parse
> HTML? The internet is full of people who thought that was
> a good idea.

Again, i did not suggested that people have never done
anything stupid with regexps, on the contrary, this list has
bear witness to many of them. My only intention was to point
out the damaging (albeit interesting) effects of propaganda.

MY WHOLE POINT IS ABOUT "PROPAGANDA"!

THAT'S IT!

DO YOU NEED ME TO DRAW YOU A PICTURE?

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


Re: Track down SIGABRT

2015-01-13 Thread Skip Montanaro
Assuming you have gdb available, you should be able to attach to the
running process, then set a breakpoint in relevant functions (like
exit() or abort()). Once there, you can pick through the C stack
manually (kind of tedious) or use the gdbinit file which comes with
Python to get a Python stack trace (much less tedious, once you've
made sure any version dependencies have been eliminated). Or, with the
latest versions of gdb (7.x I think), you get more stuff built into
gdb itself.

More details here:

https://wiki.python.org/moin/DebuggingWithGdb

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


Re: what would be the regular expression for null byte present in a string

2015-01-13 Thread Denis McMahon
On Tue, 13 Jan 2015 13:40:52 +, Shambhu Rajak wrote:

> I have a string that I get as an output of a command as:
> '\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x0010232ae8944a\x02\x00
\x00\x00\x00\x00\x00\x00\n'
> 
> I want to fetch '10232ae8944a' from the above string.
> 
> I want to find a re pattern that could replace all the \x01..\x0z to be
> replace by empty string '',  so that I can get the desired portion of
> string
> 
> Can anyone help me with a working regex for it.

What have you tried, and what was the result?

Regex isn't designed to work with byte strings.

>>> str = '\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x0010232ae8944a
\x02\x00\x00\x00\x00\x00\x00\x00\n'

>>> str.replace('\x00','').replace('\x0c','').replace('\x01','').replace
('\x02','').replace('\n','')
'10232ae8944a'

This works for the specific example you gave, will your "string" ever 
contain unwanted characters apart from \x00, \x01, \x02, \x0c, \n, and is 
it ever possible for one of those to be in the wanted set?

>>> str[12:24]
'10232ae8944a'

This also works for the specific example you gave, is the data you want 
to extract always going to be at the same offset in the string, and of 
the same length?

>>> ''.join([str[x] for x in range(len(str)) if str[x] >= ' ' and str[x] 
<= '~'])
'10232ae8944a'

This also works for the specific example you gave, and is a way to remove 
non printing and 8bit characters from a string. Is this what you actually 
want to do?

>>> str.strip('\x00\x0c\x01\x02\n')
'10232ae8944a'

This also works for the specific example that you gave, it uses the strip 
function with a string of characters to be stripped, this will work as 
long as you can predefine all the characters to strip and none of the 
characters to strip is ever desired as part of the result.

So 4 different methods, each of which seems to do, in the case of the 
specific example you gave, exactly what you want.

However although I tried a few patterns, I don't seem to be able to 
create an re that will do the job.

eg:

>>> patt = re.compile(r'[0-9a-zA-Z]+')
>>> res = patt.match(str)
>>> res
>>> print res
None
>>> type(res)


>>> patt = re.compile(r'[0-z]+')
>>> res = patt.match(str)
>>> res
>>> print res
None
>>> type(res)

>>> 

>>> patt = re.compile(r'[ -~]+')
>>> res = patt.match(str)
>>> res
>>> print res
None
>>> type(res)

>>> 

-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Track down SIGABRT

2015-01-13 Thread Israel Brewster
On Jan 13, 2015, at 8:26 AM, Skip Montanaro  wrote:

> Assuming you have gdb available, you should be able to attach to the
> running process, then set a breakpoint in relevant functions (like
> exit() or abort()). Once there, you can pick through the C stack
> manually (kind of tedious) or use the gdbinit file which comes with
> Python to get a Python stack trace (much less tedious, once you've
> made sure any version dependencies have been eliminated). Or, with the
> latest versions of gdb (7.x I think), you get more stuff built into
> gdb itself.
> 
> More details here:
> 
> https://wiki.python.org/moin/DebuggingWithGdb

Thanks, I'll look into that. Hopefully running with the debugger attached won't 
slow things down to much. The main thing I think will be getting the python 
extensions installed - the instructions only talk about doing this for linux 
packages.

> 
> Skip

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


Re: Track down SIGABRT

2015-01-13 Thread Paul Rubin
Israel Brewster  writes:
> when it again crashed with a SIGABRT. The crash dump the
> system gave me doesn't tell me much, other than that it looks
> like python is calling some C function when it crashes. I've
> attached the crash report, in case it can mean something more
> to someone else.

Somehow I missed the original post: did you get a core dump?  The
next thing to do is examine it under gdb.

> 
> Can anyone give me some hints as to how to track down the
> cause of this crash? 

If it's recurring, recompile python with -g to generate debugging
symbols, so you'll have an easier time examining the dump.  You can even
run the whole interpreter under gdb, though doing that for 33 days might
be uncharted territory.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how can I create a class and decode/encode as json?

2015-01-13 Thread Denis McMahon
On Tue, 13 Jan 2015 08:17:18 -0800, robertchen117 wrote:

> I want to send Message to rabbitmq and receive from rabbitmq, message
> format is below.
> 
> how can I create a class and decode/encode as json?

It may be easier to use dictionaries than classes.

>>> import json
>>> thing = {}
>>> thing["message"] = {}
>>> thing["message"]["dateCreated"] = "1417713299"
>>> thing["message"]["operations"] = []
>>> for i in range(3):
... bit = {}
... bit["sequence"] = i
... bit["data"] = "blah blah blah"
... thing["message"]["operations"].append(bit)
... 
>>> json.dumps(thing)
'{"message": {"operations": [{"data": "blah blah blah", "sequence": 0}, 
{"data": "blah blah blah", "sequence": 1}, {"data": "blah blah blah", 
"sequence": 2}], "dateCreated": "1417713299"}}'

-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 regex?

2015-01-13 Thread Rick Johnson
On Tuesday, January 13, 2015 at 11:09:17 AM UTC-6, Rick Johnson wrote:
> [...]
> DO YOU NEED ME TO DRAW YOU A PICTURE?

I don't normally do this, but in the interest of education
i feel i must bear the burdens for which all professional
educators like myself are responsible. 

  https://plus.google.com/114883720122692827712/posts/Nxo3rR7TwQS
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can i use a dictionnary

2015-01-13 Thread Dan Sommers
On Tue, 13 Jan 2015 06:56:11 -0800, Novocastrian_Nomad wrote:

> On Tuesday, January 13, 2015 at 2:03:30 AM UTC-7, brice DORA wrote:

>> i consume a web service that return a element whose the type is
>> "instance". but this element seem be a dictionary but when i want to
>> use it like a dictionary, i got some errors. so this is the element
>> and please someone can tell me how can i use it. tkanks in advance.
>> 
>> (tCountryInfo){
>>sISOCode = "CI"
>>sName = "Côte D'Ivoire (Ivory Coast)"
>>sCapitalCity = "Yamoussoukro"
>>sPhoneCode = "225"
>>sContinentCode = "AF"
>>sCurrencyISOCode = "XOF"
>>sCountryFlag = 
>> "http://www.oorsprong.org/WebSamples.CountryInfo/Images/Côte D'Ivoire.jpg"
>>Languages = 
>>   (ArrayOftLanguage){
>>  tLanguage[] = 
>> (tLanguage){
>>sISOCode = "fr"
>>sName = "French"
>> },
>>   }
>>  }

> This data is not a Python dictionary, nor is it a JSON object.  You
> will probably need to code your own conversion function to make it a
> Python dictionary.

This looks like the str (or maybe it's the repr) of an object returned
by the suds library.  If so, then that object has appropriate attributes
for accessing the data; please see the documentation.  What happens when
you print object.sName (assuming that your element is named "object")?

HTH,
Dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7, on windows7 64 bit development machine, inconsistent issue on similar machines

2015-01-13 Thread Jacob Kruger

See answers below.

Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."

- Original Message - 
From: "Dennis Lee Bieber" 




The very first hit /I/ get is:
https://social.technet.microsoft.com/Forums/windows/en-US/3932e3eb-c034-4eb7-aa06-4a0a8e6ea493/fault-module-namestackhash0a9e



Played around with data expraction policy changes/settings now, and didn't 
make it change behaviour.







 s_host = str(d_mysql["host"])
 s_user = str(d_mysql["user"])
 s_pass = str(d_mysql["password"])
 s_db = self.s_target_value


ONE: Have you confirmed all of these are coming in correctly

Yes - that mysql.set pickle dump is just a way of storing some string values 
relating to mysql server connection to sort of hide it from an end-user, 
but, yes, the values work fine in that sense.



 cn = MySQLdb.connect(s_host, s_user, s_pass, s_db)
 if cn:
   cn.autocommit = True


TWO-A: you've turned on autocommit here, yet...


Sorry - that was sort of left-over from when was trying to make sure that 
other parts were happening/working - along with trying out specific commit 
call lower down - have tried taking eitehr of them out one by one, to see if 
made a difference, but, no-go.





   cur = cn.cursor()
   i_struct = 0
   i_data = 0
   f = open(self.s_sql_struct_file, "rb")
   s = f.read()
   f.close()
   l_struct = s.split(";")


THREE-A: here you split some string on semicolons, just to...


   f = open(self.s_sql_data_file, "rb")
   s = f.read()
   f.close()
   l_data = unidecode(s).split(";")
   l_struct_errors = []
   l_data_errors = []
   i_start_time = int(time.time())
   s_status = "/{0} structs".format(str(len(l_struct)))
   for I in range(len(l_struct)):


Very UN-Pythonic...


I know - that was also since originally used this code in a sort of GUI 
version, and meant to use one by one counter to update status bar text at 
sort of intervals of 10 records, to let guys track progress - but, FWIW, it 
seemed to overload my screen reader with too many changes, partly since some 
of these collections of insert statements are processing over 4 record 
insertions - not currently with test data, but, some of the other test 
database files I used were operating in that region of the number of data 
record numbers. Have taken that part out again now.




for a_struct in l_struct:
# do stuff with a_struct directly, no indexing into l_struct


 try:
   i_struct = I
   if str(l_struct[I]).strip() != "": res = 
cur.execute(l_struct[I] + ";")


THREE-B: ... reappend the semicolon here... which probably isn't needed
-- cur.execute() assumes, as I recall, that the provided argument is a
complete statement; unlike a command line interface where the semicolon is
needed to tell the CLI that the statement is complete and can be sent to
the DBMS for processing.

And very confusing names... l_struct and i_struct, where the latter is
an index into the former (and I don't see it used anywhere).


Have taken out counter now, and, yes, cursor seems happy to execute 
statements without ; character at end.





   print(l_struct[I])
 #except Warning as wrn:
 #  print("warning: " + str(wrn.args))
 except Exception as exc:
   l_struct_errors.append([l_struct[I], copy.copy(exc)])
 finally:
   pass
   cn.commit()


TWO-B: ... here you attempt to force a commit.


That was also during test phase when was just trying to make sure parts of 
this were being executed/committed - taken out additional commits now.





   time.sleep(2.0)
   sNada = raw_input("hit enter to continue with data")
   s_status = "/{0} data".format(str(len(l_data)))
   for I in range(len(l_data)):
 try:
   #self.SetStatusText(str(I) + s_status)
   i_data = I
   if str(l_data[I]).strip() != "": res = 
cur.execute(l_data[I][l_data[I].index("INSERT"):] + ";")

   print(l_data[I][l_data[I].index("INSERT"):] + ";")
 except Exception as exc:
   l_data_errors.append([l_data[I], copy.copy(exc)])
 finally:
   pass
   i_end_time = int(time.time())
   s_time_taken = sTimeDiffFormat(i_start_time, i_end_time)
   cn.commit()


TWO-C: ... and here too.


   cur.close()
   cn.close()
   print("cn and cur closed")
   fPickle = open("testDataErrors.pickle", "wb")
   pickle.dump(l_struct_errors, fPickle, 2)
   pickle.dump(l_data_errors, fPickle, 2)
   fPickle.close()
   print("pickled")
   print("MySQL Results - {0} structure queries, and {1} data queries 
completed - total of {2}".format(str(i_struct), str(i_data), 
s_time_taken))
   print("MySQL Errors - {0} structure query errors, and {1} data 
query errors".format(str(len(l_struct_errors)), str(len(l_data_errors

   print("Done!")
   sys.exit()
   

Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Ian Kelly
On Tue, Jan 13, 2015 at 4:20 AM, Chris Angelico  wrote:
> On Tue, Jan 13, 2015 at 10:00 PM, Marko Rauhamaa  wrote:
>> The code above, though, shouldn't consume memory since it is a simple
>> tail-recursive loop.
>
> Only if the interpreter can optimize it away. Bear in mind that it
> doesn't _return_ the result of that expression, so it needs to take
> whatever f() returns, discard it, and return None.

And CPython doesn't even try to optimize tail recursion anyway.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Chris Angelico
On Wed, Jan 14, 2015 at 5:56 AM, Ian Kelly  wrote:
> On Tue, Jan 13, 2015 at 4:20 AM, Chris Angelico  wrote:
>> On Tue, Jan 13, 2015 at 10:00 PM, Marko Rauhamaa  wrote:
>>> The code above, though, shouldn't consume memory since it is a simple
>>> tail-recursive loop.
>>
>> Only if the interpreter can optimize it away. Bear in mind that it
>> doesn't _return_ the result of that expression, so it needs to take
>> whatever f() returns, discard it, and return None.
>
> And CPython doesn't even try to optimize tail recursion anyway.

I presumed that Marko's "shouldn't" was "CPython should be smarter than this".

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


Re: Python 2.7, on windows7 64 bit development machine, inconsistent issue on similar machines

2015-01-13 Thread Jacob Kruger
Ok, and just tested MySQLdb connection to both XAMPP server instance on same 
machine, as well as slightly remote connection to other machine over wifi, 
and same error - so, seems issue is invoked/caused by MySQLdb connection 
closing - if just put process to sleep for 30 seconds, nothing happens, but, 
the moment I in fact try to then just close the connection, that's when 
error dialogue immediately pops up.


Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."

- Original Message - 
From: "Jacob Kruger" 

To: "Dennis Lee Bieber" 
Cc: 
Sent: Tuesday, January 13, 2015 8:37 PM
Subject: Re: Python 2.7, on windows7 64 bit development machine, 
inconsistent issue on similar machines




See answers below.

Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."

- Original Message - 
From: "Dennis Lee Bieber" 




The very first hit /I/ get is:
https://social.technet.microsoft.com/Forums/windows/en-US/3932e3eb-c034-4eb7-aa06-4a0a8e6ea493/fault-module-namestackhash0a9e



Played around with data expraction policy changes/settings now, and didn't 
make it change behaviour.







 s_host = str(d_mysql["host"])
 s_user = str(d_mysql["user"])
 s_pass = str(d_mysql["password"])
 s_db = self.s_target_value


ONE: Have you confirmed all of these are coming in correctly

Yes - that mysql.set pickle dump is just a way of storing some string 
values relating to mysql server connection to sort of hide it from an 
end-user, but, yes, the values work fine in that sense.



 cn = MySQLdb.connect(s_host, s_user, s_pass, s_db)
 if cn:
   cn.autocommit = True


TWO-A: you've turned on autocommit here, yet...


Sorry - that was sort of left-over from when was trying to make sure that 
other parts were happening/working - along with trying out specific commit 
call lower down - have tried taking eitehr of them out one by one, to see 
if made a difference, but, no-go.





   cur = cn.cursor()
   i_struct = 0
   i_data = 0
   f = open(self.s_sql_struct_file, "rb")
   s = f.read()
   f.close()
   l_struct = s.split(";")


THREE-A: here you split some string on semicolons, just to...


   f = open(self.s_sql_data_file, "rb")
   s = f.read()
   f.close()
   l_data = unidecode(s).split(";")
   l_struct_errors = []
   l_data_errors = []
   i_start_time = int(time.time())
   s_status = "/{0} structs".format(str(len(l_struct)))
   for I in range(len(l_struct)):


Very UN-Pythonic...


I know - that was also since originally used this code in a sort of GUI 
version, and meant to use one by one counter to update status bar text at 
sort of intervals of 10 records, to let guys track progress - but, FWIW, 
it seemed to overload my screen reader with too many changes, partly since 
some of these collections of insert statements are processing over 4 
record insertions - not currently with test data, but, some of the other 
test database files I used were operating in that region of the number of 
data record numbers. Have taken that part out again now.




for a_struct in l_struct:
# do stuff with a_struct directly, no indexing into l_struct


 try:
   i_struct = I
   if str(l_struct[I]).strip() != "": res = 
cur.execute(l_struct[I] + ";")


THREE-B: ... reappend the semicolon here... which probably isn't needed
-- cur.execute() assumes, as I recall, that the provided argument is a
complete statement; unlike a command line interface where the semicolon 
is

needed to tell the CLI that the statement is complete and can be sent to
the DBMS for processing.

And very confusing names... l_struct and i_struct, where the latter is
an index into the former (and I don't see it used anywhere).


Have taken out counter now, and, yes, cursor seems happy to execute 
statements without ; character at end.





   print(l_struct[I])
 #except Warning as wrn:
 #  print("warning: " + str(wrn.args))
 except Exception as exc:
   l_struct_errors.append([l_struct[I], copy.copy(exc)])
 finally:
   pass
   cn.commit()


TWO-B: ... here you attempt to force a commit.


That was also during test phase when was just trying to make sure parts of 
this were being executed/committed - taken out additional commits now.





   time.sleep(2.0)
   sNada = raw_input("hit enter to continue with data")
   s_status = "/{0} data".format(str(len(l_data)))
   for I in range(len(l_data)):
 try:
   #self.SetStatusText(str(I) + s_status)
   i_data = I
   if str(l_data[I]).strip() != "": res = 
cur.execute(l_data[I][l_data[I].index("INSERT"):] + ";")

   print(l_data[I][l_data[I].index("INSERT"):] + ";")
 except Exception as exc:
   l_data_errors.append([l_data[I], copy.copy(exc)])
 finally:

Re: Performance in exec environnements

2015-01-13 Thread Ian Kelly
On Tue, Jan 13, 2015 at 10:02 AM, Jean-Baptiste Braun
 wrote:
> Hi,
>
> I'm working on auto-generated python code with the exec function. I've done
> some performance benches :
>
> % python -m timeit '1 + 1'
> 1000 loops, best of 3: 0.0229 usec per loop
>
> % python -m timeit "exec('1 + 1')"
> 10 loops, best of 3: 11.6 usec per loop
>
> -> Maybe creating an exec environnement (I don't know how it works) takes
> time. But :
>
> % python -m timeit "1 + 1; 1 + 1"
> 1000 loops, best of 3: 0.042 usec per loop
>
> % python -m timeit "exec('1 + 1; 1 + 1')"
> 10 loops, best of 3: 15.7 usec per loop
>
> -> As if executing one more 1 + 1 would take 4 more seconds (10
> iterations) in an exec environnement.
>
> Am I missing something or should I expect that result ? What does using exec
> imply that causes such a difference ?

Since you're execing a string, the string has to be compiled each time
exec is called. In contrast, the 1 + 1 in the timeit loop is only
compiled once.

C:\Users\Ian>python -m timeit "1 + 1"
1000 loops, best of 3: 0.0397 usec per loop

C:\Users\Ian>python -m timeit "exec('1 + 1')"
10 loops, best of 3: 17 usec per loop

C:\Users\Ian>python -m timeit "compile('1 + 1', '', 'exec')"
10 loops, best of 3: 17 usec per loop

C:\Users\Ian>python -m timeit -s "c = compile('1 + 1', '', 'exec')" "exec(c)"
100 loops, best of 3: 0.684 usec per loop

I expect the function call probably accounts for most of the rest of
the difference.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-13 Thread André Roberge
On Tuesday, 13 January 2015 08:23:30 UTC-4, [email protected]  wrote:
> I found a solution that I'm happy with.
> 
> from datetime import datetime
> from easygui_qt import *
> 
> datestring = get_date()
> mydate = datetime.strptime(datestring, '%b %d %Y')

I'm thinking of having the new version return a datetime object automatically.

André

> 
> On Saturday, January 10, 2015 at 1:02:30 AM UTC, André Roberge wrote:
> > On Friday, 9 January 2015 19:09:15 UTC-4, [email protected]  wrote:
> > > On Wednesday, December 31, 2014 at 4:24:50 PM UTC-6, André Roberge wrote:
> > > > EasyGUI_Qt version 0.9 has been released.  This is the first 
> > > > announcement about EasyGUI_Qt on this list.
> > > > 
> > > > Like the original EasyGUI (which used Tkinter), 
> > > > EasyGUI_Qt seeks to provide simple GUI widgets
> > > > that can be called in a procedural program. 
> > > > 
> > > > EasyGUI_Qt is NOT event-driven: all GUI interactions are invoked by 
> > > > simple function calls.
> > > > 
> > > > The archetype is get_string(message)
> > > > which pops a box whose purpose is exactly the same as Python's 
> > > > input(prompt),
> > > > that is, present the user with a question/prompt, have the user enter an
> > > > answer, and return the provided answer as a string.  Thus
> > > > easygui_qt.get_string() can be used as a drop-in replacement for
> > > > input().
> > > > 
> > > > Similarly, instead of using a print() function to display a message,
> > > > show_message() is used which pops a message window.
> > > > 
> > > > EasyGUI_Qt requires PyQt4 and is really targeted for Python 3.3+ - 
> > > > although it can work (possibly with some unicode problems ...) using 
> > > > Python 2.7.
> > > > 
> > > > More information can be found at 
> > > > http://easygui-qt.readthedocs.org/en/latest/index.html
> > > > 
> > > > Feedback is most welcome, including reporting bugs to 
> > > > https://github.com/aroberge/easygui_qt/issues
> > > > 
> > > > Happy 2015 everyone,
> > > > 
> > > > André Roberge
> > > 
> > > Very nice, thanks.
> > > 
> > > One issue is the format returned for the calendar selection. For today, 
> > > the string returned is "Fri Jan 9 2015". My script needs to convert the 
> > > date to a datetime.date, and having the month returned as a string 
> > > instead of an integer makes this harder.
> > 
> > Would today's date be represented as the string "09.01.2015" useful to you? 
> > (I found out how to do this.)  If so, I could perhaps add an argument like 
> > numeric_format = True.
> > 
> > André

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


ANN: Python Events Calendar - Please submit your 2015 events

2015-01-13 Thread M.-A. Lemburg
[Please help spread the word by forwarding to other relevant mailing lists,
 user groups, etc. world-wide; thanks :-)]


ANNOUNCING

 Python Events Calendars - Please submit your 2015 events

   maintained by the Python Software Foundation (PSF)
and a group of volunteers


INTRODUCTION

As some of you may know, the PSF has a team of volunteers who are
maintaining a set of central Python event calendars. We currently have
two calendars in place:

 * Python Events Calendar - meant for conferences and larger gatherings
   focusing on Python or a related technology (in whole or in part)

 * Python User Group Calendar - meant for user group events and other
   smaller local events

The calendars are displayed on http://pycon.org/ and also on the new
https://python.org/ website at https://www.python.org/events/python-events/
and https://www.python.org/events/python-user-group/.

You can subscribe to the calendars using iCal and RSS feeds and also
embed the calendar widgets on your sites. We have also added a
Twitter feed @PythonEvents to get immediate updates whenever a new
event is added. Please see our wiki page for details:

   https://wiki.python.org/moin/PythonEventsCalendar

The calendars are open to the world-wide Python community, so you
can have local user group events, as well as regional and
international conference events added to the calendars.


NEWS

Looking back on 2014, the calendars have proven to be a great tool
for the Python community to connect, with more than 60 conferences
and more than a hundred of user group events listed.

We would therefore like to encourage everyone to submit their
2015 events, so that the Python community can get a better overview
over what's happening in Python land.


ADDING EVENTS

Please see the instructions at 
https://wiki.python.org/moin/PythonEventsCalendar#Available_Calendars
for details on how to
submit an event. We've made it really easy for you: just need to send
an email to our team address using the email template we
provide for this. Thanks.


MORE INFORMATION

More information on the calendars, the URLs, feed links, IDs, embedding,
etc. is available on the wiki:

https://wiki.python.org/moin/PythonEventsCalendar

Enjoy,
-- 
Marc-Andre Lemburg
Director
Python Software Foundation
http://www.python.org/psf/

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


Re: Python Events Calendar - Please submit your 2015 events

2015-01-13 Thread Stéphane Wirtel

Hi Marc-André,

In fact, during the PythonFOSDEM 2015, there will be a presentation with 
the future events in 2015.

I will use the python-events calendar for that.

So, in this case, I propose to all the organisers of conferences to 
submit as soon as possible the calendar of their events.


Thank you for your message,

Stephane

On 13 Jan 2015, at 22:18, M.-A. Lemburg wrote:

[Please help spread the word by forwarding to other relevant mailing 
lists,

user groups, etc. world-wide; thanks :-)]


ANNOUNCING

  Python Events Calendars - Please submit your 2015 events

maintained by the Python Software Foundation (PSF)
 and a group of volunteers


INTRODUCTION

As some of you may know, the PSF has a team of volunteers who are
maintaining a set of central Python event calendars. We currently have
two calendars in place:

* Python Events Calendar - meant for conferences and larger gatherings
focusing on Python or a related technology (in whole or in part)

* Python User Group Calendar - meant for user group events and other
smaller local events

The calendars are displayed on http://pycon.org/ and also on the new
https://python.org/ website at 
https://www.python.org/events/python-events/

and https://www.python.org/events/python-user-group/.

You can subscribe to the calendars using iCal and RSS feeds and also
embed the calendar widgets on your sites. We have also added a
Twitter feed @PythonEvents to get immediate updates whenever a new
event is added. Please see our wiki page for details:

https://wiki.python.org/moin/PythonEventsCalendar

The calendars are open to the world-wide Python community, so you
can have local user group events, as well as regional and
international conference events added to the calendars.


NEWS

Looking back on 2014, the calendars have proven to be a great tool
for the Python community to connect, with more than 60 conferences
and more than a hundred of user group events listed.

We would therefore like to encourage everyone to submit their
2015 events, so that the Python community can get a better overview
over what's happening in Python land.


ADDING EVENTS

Please see the instructions at 
https://wiki.python.org/moin/PythonEventsCalendar#Available_Calendars

for details on how to
submit an event. We've made it really easy for you: just need to send
an email to our team address using the email template we
provide for this. Thanks.


MORE INFORMATION

More information on the calendars, the URLs, feed links, IDs, 
embedding,

etc. is available on the wiki:

 https://wiki.python.org/moin/PythonEventsCalendar

Enjoy,
--
Marc-Andre Lemburg
Director
Python Software Foundation
http://www.python.org/psf/

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



--
Stéphane Wirtel - http://wirtel.be - @matrixise
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Events Calendar - Please submit your 2015 events

2015-01-13 Thread M.-A. Lemburg
On 13.01.2015 22:24, =?utf-8?q?St=C3=A9phane?= Wirtel wrote:
> Hi Marc-André,
> 
> In fact, during the PythonFOSDEM 2015, there will be a presentation with the 
> future events in 2015.
> I will use the python-events calendar for that.
> 
> So, in this case, I propose to all the organisers of conferences to submit as 
> soon as possible the
> calendar of their events.

That would be great ! Thanks.

> Thank you for your message,
> 
> Stephane
> 
> On 13 Jan 2015, at 22:18, M.-A. Lemburg wrote:
> 
>> [Please help spread the word by forwarding to other relevant mailing lists,
>> user groups, etc. world-wide; thanks :-)]
>>
>> 
>> ANNOUNCING
>>
>>   Python Events Calendars - Please submit your 2015 events
>>
>> maintained by the Python Software Foundation (PSF)
>>  and a group of volunteers
>>
>> 
>> INTRODUCTION
>>
>> As some of you may know, the PSF has a team of volunteers who are
>> maintaining a set of central Python event calendars. We currently have
>> two calendars in place:
>>
>> * Python Events Calendar - meant for conferences and larger gatherings
>> focusing on Python or a related technology (in whole or in part)
>>
>> * Python User Group Calendar - meant for user group events and other
>> smaller local events
>>
>> The calendars are displayed on http://pycon.org/ and also on the new
>> https://python.org/ website at https://www.python.org/events/python-events/
>> and https://www.python.org/events/python-user-group/.
>>
>> You can subscribe to the calendars using iCal and RSS feeds and also
>> embed the calendar widgets on your sites. We have also added a
>> Twitter feed @PythonEvents to get immediate updates whenever a new
>> event is added. Please see our wiki page for details:
>>
>> https://wiki.python.org/moin/PythonEventsCalendar
>>
>> The calendars are open to the world-wide Python community, so you
>> can have local user group events, as well as regional and
>> international conference events added to the calendars.
>>
>> 
>> NEWS
>>
>> Looking back on 2014, the calendars have proven to be a great tool
>> for the Python community to connect, with more than 60 conferences
>> and more than a hundred of user group events listed.
>>
>> We would therefore like to encourage everyone to submit their
>> 2015 events, so that the Python community can get a better overview
>> over what's happening in Python land.
>>
>> 
>> ADDING EVENTS
>>
>> Please see the instructions at 
>> https://wiki.python.org/moin/PythonEventsCalendar#Available_Calendars
>> for details on how to
>> submit an event. We've made it really easy for you: just need to send
>> an email to our team address using the email template we
>> provide for this. Thanks.
>>
>> 
>> MORE INFORMATION
>>
>> More information on the calendars, the URLs, feed links, IDs, embedding,
>> etc. is available on the wiki:
>>
>>  https://wiki.python.org/moin/PythonEventsCalendar
>>
>> Enjoy,
>> -- 
>> Marc-Andre Lemburg
>> Director
>> Python Software Foundation
>> http://www.python.org/psf/
>>
>> -- 
>> https://mail.python.org/mailman/listinfo/python-list
> 
> 
> -- 
> Stéphane Wirtel - http://wirtel.be - @matrixise

-- 
Marc-Andre Lemburg
Director
Python Software Foundation
http://www.python.org/psf/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Performance in exec environnements

2015-01-13 Thread Steven D'Aprano
Jean-Baptiste Braun wrote:

> Hi,
> 
> I'm working on auto-generated python code with the exec function. I've
> done some performance benches :

[snip timing results]

> Am I missing something or should I expect that result ? What does using
> exec imply that causes such a difference ?

exec'ing a string will be slower than directly executing code.

Firstly, your initial test:

python -m timeit "1 + 1"

 is probably biased. Python has a keyhole optimizer which does constant
folding, so that is equivalent to:

python -m timeit "2"

which does very little work. To get a more realistic timing, try this:

python -m timeit "n = 1; n + 1"

which will defeat the peephole optimizer.

So you have been comparing:

2

versus

exec('1+1')


The first case just fetches a reference to a pre-existing int object, and
then deletes the reference. That's fast.

The second case:

- creates a new string '1+1'
- does a global lookup to find the built-in exec function
- passes the string to the function
- the function then parses that string and compiles it to byte-code
- runs the keyhole optimizer over it
- and finally executes the byte code for "2", same as above.

Only the last step is the same as your earlier test case.


In my experience, the difference between running a piece of code, and
running the same code as a string passed to exec, will be *at least* a
factor of 10 slowdown.

Sometimes you can speed things up by pre-compiling code with compile(), or
with little micro-optimization tricks such as:

def f():
for x in seq:
exec(x)  # Looks up the global exec many times.


def f():
ex = exec  # Look up the global once.
for x in seq:
ex(x)  # fast local variable lookup


But that is a micro-optimization which might shave off a few microseconds
per loop, don't expect it to give big savings.

Bigger savings come from avoiding exec. Instead, try to use factory
functions, closures, etc. If you give an example of what you are trying to
generate with exec, we may be able to offer an alternative.



-- 
Steven

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


Re: List of "python -m" tools

2015-01-13 Thread Irmen de Jong
On 12-1-2015 5:17, Miki Tebeka wrote:
> Greetings,
> 
> I've compiled a list of "python -m" tools at 
> pythonwise.blogspot.com/2015/01/python-m.html.
> 
> Did I miss something? What are your favorite "python -m" tools?
> 
> Thanks,
> --
> Miki
> 


python -m calendar
python -m test.pystone
python -m antigravity


Irmen

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


Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Andrew Robinson


On 01/12/2015 09:32 PM, Steven D'Aprano wrote:

On Mon, 12 Jan 2015 17:59:42 -0800, Andrew Robinson wrote:

[...]

What I am wanting to know is WHY did Guido think it so important to do
that ?   Why was he so focused on a strict inability to have any
instances of a bool subclass at all -- that he made a very arbitrary
exception to the general rule that base types in Python can be
subclassed ?

It's not arbitrary. All the singleton (doubleton in the case of bool)
classes cannot be subclassed. E.g. NoneType:

py> class X(type(None)):
... pass
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: Error when calling the metaclass bases
 type 'NoneType' is not an acceptable base type


Likewise for the NotImplemented and Ellipsis types.

The reason is the same: if a type promises that there is one and only one
instance (two in the case of bool), then allowing subtypes will break
that promise in the 99.99% of cases where the subtype is instantiated.
Ok. That's something I did not know.  So much for the just four classes 
can't be subtyped remark someone else made...


At least Guido is consistent.
But that doesn't give me any idea of why he thought it important.


I suppose in principle Python could allow you to subclass singleton
classes to your hearts content, and only raise an error if you try to
instantiate them, but that would probably be harder and more error-prone
to implement, and would *definitely* be harder to explain.


There may be others too:

py> from types import FunctionType
py> class F(FunctionType):
... pass
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: Error when calling the metaclass bases
 type 'function' is not an acceptable base type


My guess here is that functions are so tightly coupled to the Python
interpreter that allowing you to subclass them, and hence break required
invariants, could crash the interpreter. Crashing the interpreter from
pure Python code is *absolutely not allowed*, so anything which would
allow that is forbidden.



There's no reason in object oriented programming principles in general
that requires a new subclass instance to be a COMPLETELY DISTINCT
instance from an already existing superclass instance

True. But what is the point of such a subclass? I don't think you have
really thought this through in detail.


I have. Such a subclass allows refining of the meaning/precision of a 
previous type while improving compatibility with existing applications 
-- and without being so easy to do that everyone will abuse it.  That's 
the standard kind of things which go into deciding that a singleton is 
appropriate...


Subclasses of singletons is a tried and true way of improving 
productivity regardless of how it is implemented.



Suppose we allowed bool subclasses, and we implement one which *only*
returns True and False, without adding a third instance:

class MyBool(bool):
 def __new__(cls, arg):
 if cls.condition(arg):
 return True
 else:
 return False
 @classmethod
 def condition(cls, obj):
 # decide whether obj is true-ish or false-ish.
 pass
 def spam(self):
 return self.eggs()
 def eggs(self):
 return 23


And then you do this:

flag = MyBool(something)
flag.spam()


What do you expect to happen?

Flag is not an instance of MyBool, so it's going to generate an exception.


Since flag can *only* be a regular bool, True or False, it won't have
spam or eggs methods.

Correct.  It would generate an exception.

You might think of writing the code using unbound methods:

MyBool.spam(flag)

(assuming that methods don't enforce the type restriction that "self"
must be an instance of their class), but that fails when the spam method
calls "self.eggs". So you have to write your methods like this:

 def spam(self):
 return MyBool.eggs(self)

hard-coding the class name! You can't use type(self), because that's
regular bool, not MyBool.

This is a horrible, error-prone, confusing mess of a system. If you're
going to write code like this, you are better off making MyBool a module
with functions instead of a class with methods.


Every design method has its trade offs... but how you organize you code 
will affect whether it is messy or clean.


In terms of information encoding -- both an instance of a type,  or a 
class definition held in a type variable -- eg: a class name -- are 
pretty much interchangeable when it comes to being able to tell two 
items are not the same one, or are the same one.


So -- even a cursory thought shows that the information could be encoded 
in a very few lines even without an instance of a subclass:


class CAllFalse():
@classmethod
def __nonzero__(Kls): return False

class CPartFalse():
@classmethod
def __nonzero__(Kls): return False

...

class cmp():
lex=( CAllFalse,  CPartFalse, True )
@staticmethod
def __cmp__( left, right ):
if type

Compiling multiple python scripts into an exe file

2015-01-13 Thread no nein
Basically, is it possible to compile multiple unrelated python scripts into a 
single exe file, so when execute it several python programs are run at once.
In order to use this on another machine without python installed and only by 
using one single file.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-01-13 Thread Peng Yu
Hi,

I am trying to understand what does encode() do. What are the hex
representations of "u" in main.py? Why there is UnicodeEncodeError
when main.py is piped to xxd? Why there is no such error when it is
not piped? Thanks.

~$ cat main.py
#!/usr/bin/env python

u = unichr(40960) + u'abcd' + unichr(1972)
print u
~$ cat main_encode.py
#!/usr/bin/env python

u = unichr(40960) + u'abcd' + unichr(1972)
print u.encode('utf-8')
$ ./main.py
ꀀabcd޴
~$ cat main.sh
#!/usr/bin/env bash

set -v
./main.py | xxd
./main_encode.py | xxd

~$ ./main.sh
./main.py | xxd
Traceback (most recent call last):
  File "./main.py", line 4, in 
print u
UnicodeEncodeError: 'ascii' codec can't encode character u'\ua000' in
position 0: ordinal not in range(128)
./main_encode.py | xxd
000: ea80 8061 6263 64de b40a ...abcd...

-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] ‘python-daemon’ version 2.0.3 released

2015-01-13 Thread Ben Finney
Howdy all,

I am pleased to announce the release of version 2.0.3 of the
‘python-daemon’ library.

The current release is always available at
https://pypi.python.org/pypi/python-daemon/>.

The project's forums and VCS are hosted at Alioth
https://alioth.debian.org/projects/python-daemon/>.


Significant changes since the previous version
==

This is a bug fix release, addressing packaging bugs:

* Break circular import dependency for ‘setup.py’.

Many thanks to users who promptly reported this bug.


What is the ‘python-daemon’ library?


‘python-daemon’ is a Python library to implement a well-behaved Unix
daemon process.

-- 
 \“To me, boxing is like a ballet, except there's no music, no |
  `\   choreography, and the dancers hit each other.” —Jack Handey |
_o__)  |
Ben Finney 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7, on windows7 64 bit development machine, inconsistent issue on similar machines

2015-01-13 Thread Jacob Kruger
Ok, and just tested MySQLdb connection to both XAMPP server instance on 
same machine, as well as slightly remote connection to other machine over 
wifi, and same error - so, seems issue is invoked/caused by MySQLdb 
connection closing - if just put process to sleep for 30 seconds, nothing 
happens, but, the moment I in fact try to then just close the connection, 
that's when error dialogue immediately pops up.


Sorry - should also have mentioned the connection, cursor, etc. ec. all work 
fine under normal python interpreter, but anyway.


Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."


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


Threading in Python, Please check the script

2015-01-13 Thread Robert Clove
Hi All,

I have made a script in which i have started two thread named thread 1 and
thread 2.
In thread 1 one function will run named func1 and in thread 2 function 2
will run named func 2.
Thread 1 will execute a command and wait for 60 seconds.
Thread 2 will run only till thread 1 is running .
Again after that the same process continues in while after a break of 80
Seconds.

I am a beginner in python.
Please suggest what all i have done wrong and how to correct it.


#!/usr/bin/python

import threading
import time
import subprocess
import datetime
import os
import thread

thread.start_new_thread( print_time, (None, None))
thread.start_new_thread( print_time1, (None, None))
command= "strace -o /root/Desktop/a.txt -c ./server"
final_dir = "/root/Desktop"
exitflag = 0
# Define a function for the thread
def print_time(*args):
os.chdir(final_dir)
print "IN first thread"
proc = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.wait(70)
exitflag=1

def print_time1(*args):
print "In second thread"
global exitflag
while exitflag:
thread.exit()
#proc =
subprocess.Popen(command1,shell=True,stdout=subprocess.PIPE,
sterr=subprocess.PIPE)



# Create two threads as follows
try:
while (1):
t1=threading.Thread(target=print_time)
t1.start()
t2=threading.Thread(target=print_time1)
t2=start()
time.sleep(80)
z = t1.isAlive()
z1 = t2.isAlive()
if z:
z.exit()
if z1:
z1.exit()
   threading.Thread(target=print_time1).start()
   threading.Thread(target=print_time1).start()
print "In try"
except:
   print "Error: unable to start thread"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compiling multiple python scripts into an exe file

2015-01-13 Thread dieter
no nein  writes:

> Basically, is it possible to compile multiple unrelated python scripts into a 
> single exe file, so when execute it several python programs are run at once.

These are two distinct problems:

  *  for doing things in paralell, look at "threading" or "multiprocessing"
  *  for generating exe files, look at "freeze".

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