Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-24 Thread Frank Millman

"Dennis Lee Bieber"  wrote in message 
news:8d747a5biq4rc559tvgju088508bp0o...@4ax.com...
> On Sun, 23 Nov 2014 10:21:48 +0200, "Frank Millman" 
> declaimed the following:
>
>>
>>
>>The default is for sqlite3 to ignore foreign key contraints.
>>
[...]
>>
>>Unfortunately it has a limitation, which they acknowledge but they say is
>>unlikely to be addressed. You can access more than one database 
>>concurrently
>>by using the 'attach' command, and qualifying a remote tablename as
>>{database} dot {tablename}. You can then include the remote table in any 
>>sql
>>command. However, it will not enforce foreign key constraints across
>>databases.
>>
> Seems acceptable-- as such enforcement would require it to
> automatically reattach (likely in both directions) any/all attached
> databases when a change is made. Imagine the thrashing if one has some
> master database in a read-only mode for most users, and each user has some
> child database referencing some field in the master... And the owner of 
> the
> master database deletes a record...
>
> Are they suddenly going to have to have update capability on every
> user's database to check/enforce multi-db references?

I will explain why such a feature would have been useful for me.

My accounting system handles multiple companies. I needed to figure out a 
way to keep each one's data separate from the others.

Originally I supported two databases - PostgreSQL and Sql Server. They both 
have a concept called 'schemas', which handles my requirement elegantly - 
each company's data is stored in its own schema.

When I decided to add sqlite3 as a third option, I found that they did not 
have 'schemas'. However, I could get very close by creating multiple 
databases and using 'attach' to access them from one central database.

Overall I have been very impressed with how 'complete' sqlite3 is. The 
limitation mentioned above is one of the few compromises I have had to make. 
The sql syntax used by PostgreSQL and sqlite3 is virtually identical. I 
found more variations between PostgreSQL and Sql Server.

Frank



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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson
I am defining a single class with a destructor method that prints ‘__del__’, 
and running that source code string using exec with the module’s dict like so:

import rtmidi
import sys
import types
import time
import gc

s = """ 
  
class A:
  
def __del__(self):  
  
print('__del__')
  
a = A() 
  
"""

m = types.ModuleType('mine')
exec(s, m.__dict__)
print('deleting...')
m = None
print('done')

and the output is:

deleting...
done
__del__

I the “__del__" to come between “deleting…” and “done”. This is not being run 
from the interactive interpreter by via a .py file.

> On Nov 23, 2014, at 12:56 AM, Ian Kelly  wrote:
> 
> On Sun, Nov 23, 2014 at 2:48 AM, Ian Kelly  wrote:
>> On Sat, Nov 22, 2014 at 11:49 PM, Patrick Stinson  
>> wrote:
>>> If I create a module with imp.new_module(name), how can I unload it so that 
>>> all the references contained in it are set to zero and the module is 
>>> deleted? deleting the reference that is returned doesn’t seem to do the 
>>> job, and it’s not in sys.modules, so where is the dangling reference?
>> 
>> How are you determining that the module is not deleted?
> 
> From my testing, using Python 3.4:
> 
 for i in range(5): imp.new_module('spam')
> ...
> 
> 
> 
> 
> 
 import gc, types
 [m for m in gc.get_objects() if isinstance(m, types.ModuleType) and 
 m.__name__ == 'spam']
> []
 42
> 42
 [m for m in gc.get_objects() if isinstance(m, types.ModuleType) and 
 m.__name__ == 'spam']
> []
> 
> In this case one of the created modules was hanging around because it
> was still referenced by the special "_" variable of the interactive
> interpreter. Evaluating a new expression cleared that out and deleted
> the module. Maybe you're seeing the same thing.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Embedded python 'scripting engine' inside Python app

2014-11-24 Thread Patrick Stinson
Thanks for your great reply. I even augmented the reloading with the same dict 
by clearing all of the non-standard symbols from the dict. This effectively 
resets the dict:

# try to clear out the module by deleting all global refs   

d = self.module.__dict__
for k in dict(d).keys():
if not k in ['__spec__', '__name__', '__loader__', '__package__', 
'__doc__', '__builtins__']:
del d[k]
self.module.__dict__['sendMessage'] = self.sendMessage
try:
exec(self.source, self.module.__dict__)
except Exception:
import traceback
traceback.print_exc(file=sys.stdout)


Is there a better and more secure way to do the python-within-python in order 
allow users to automate your app?

Thanks!


> On Nov 23, 2014, at 12:24 AM, Chris Angelico  wrote:
> 
> On Sun, Nov 23, 2014 at 4:48 PM, Patrick Stinson  
> wrote:
>> I am writing a python app (using PyQt, but that’s not important here), and 
>> want my users to be able to write their own scripts to automate the app’s 
>> functioning using an engine API hat I expose. I have extensive experience 
>> doing this in a C++ app with the CPython api, but have no idea how to do 
>> this outside of calling exec() from with in Python :)
>> 
>> Ideally their script would compile when the source changes and retain it’s 
>> state and respond to callbacks from the api object. It appears this won’t 
>> work with exec() because the script’s definitions and state disappear as 
>> soon as the exec() call is complete, and the script doesn’t seem to be able 
>> to access it’s own defined functions and classes.
>> 
>> Thoughts? Fun stuff!
> 
> First off, a cautionary note: Security-wise, this is absolutely
> equivalent to your users editing your source code. Be aware that
> you're giving them complete control.
> 
> What you should be able to do is exec the script in a specific global
> dictionary. Here's some example code (Python 3.4):
> 
 script = """
> def init():
>print("Initializing")
> 
> def on_some_event(status):
>trigger_some_action("Status is now "+status)
> """
 def trigger_some_action(msg):
>print("Action triggered.",msg)
 globl = {"trigger_some_action":trigger_some_action}
 exec(script,globl)
 globl["init"]()
> Initializing
 globl["on_some_event"]("Something happened")
> Action triggered. Status is now Something happened
> 
> You can provide globals like this, or you can create an importable
> module for the scripts to call on. (Or both. Create a module, and
> pre-import it automatically.) The script defines functions with
> specific names and/or calls your functions to register hooks; you can
> reach into the globals to trigger functions.
> 
> One way to handle updates to the code would be to exec it in the same
> globals dictionary. That has its complexities (for instance, if you
> rename a function, the old version will still exist under the old name
> unless you explicitly del it), but it can be very convenient.
> Alternatively, you could have the new version run in a new dictionary,
> but important state can be kept in separate dictionaries. That's how I
> manage things with a Pike program - all code gets reloaded cleanly,
> but retained state is stored separately in a mutable object that gets
> passed around.
> 
> There are several ways this sort of thing can be done. It's reasonably
> easy, as long as you take a bit of care across the reload boundaries.
> 
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson
Basically, I have an app and am making it possible for the users to automate it 
by writing python scripts that run against the app's API. It includes PyQt5 
widgets, a QScintilla editor, and a simple API for I/O. Apple’s app store is 
the plan.

Right now I create a new module with types.ModuleType(‘something’), then exec 
the code in the module’s dict. Then when the user saves the script again in my 
editor, it deletes all top-level references in the module’s dict that don’t 
belong to the core list: ['__spec__', '__name__', '__loader__', '__package__', 
'__doc__', '__builtins__’] before running exec again. 

So far this seems to effectively “delete” the old module and re-compile it with 
the updated source. For example I can create Qt Widgets on the module level and 
they are safely deleted when the script is saved.


> On Nov 23, 2014, at 5:56 PM, Ned Batchelder  wrote:
> 
> On 11/23/14 1:49 AM, Patrick Stinson wrote:
>> If I create a module with imp.new_module(name), how can I unload it so that 
>> all the references contained in it are set to zero and the module is 
>> deleted? deleting the reference that is returned doesn’t seem to do the job, 
>> and it’s not in sys.modules, so where is the dangling reference?
>> 
>> Thanks!
>> 
> 
> This sounds tricky, and possible very difficult to do properly.  Do you mind 
> if I ask what the larger problem is?  Python might not be very good at having 
> modules come and go as you want.
> 
> -- 
> Ned Batchelder, http://nedbatchelder.com
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Embedded python 'scripting engine' inside Python app

2014-11-24 Thread Patrick Stinson
I think this is the way I’ll take it, and for all the same reasons. The only 
way they can break it is if they really want to. I guess anything other 
Franken-apps would be interesting to hear about too. And I’ll still stick it on 
the app store.


> On Nov 23, 2014, at 1:35 AM, Chris Angelico  wrote:
> 
> On Sun, Nov 23, 2014 at 9:28 PM, Patrick Stinson  
> wrote:
>> Thanks for your great reply. I even augmented the reloading with the same
>> dict by clearing all of the non-standard symbols from the dict. This
>> effectively resets the dict:
> 
> You may as well start with an empty dict and then pick up the few
> things you want, I think.
> 
>> Is there a better and more secure way to do the python-within-python in
>> order allow users to automate your app?
> 
> More secure? Basically no. You could push the inner script into a
> separate process, but I would recommend simply acknowledging the
> insecurity. Embrace the lack of security and call it a debugging
> feature - make it possible to introspect, control, manipulate internal
> structures. Feature, not flaw. :)
> 
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson
How does the __del__ method have a reference to the module’s globals dict? 
because it references the print function?

Crazy. Is there any other way to comfort when a module is being deleted beside 
defining a class object with a printing dtor?


> On Nov 23, 2014, at 4:27 PM, Ian Kelly  wrote:
> 
> 
> On Nov 23, 2014 4:10 AM, "Patrick Stinson"  > wrote:
> > m = types.ModuleType('mine')
> > exec(s, m.__dict__)
> > print('deleting...')
> > m = None
> > print('done')
> >
> > and the output is:
> >
> > deleting...
> > done
> > __del__
> >
> > I the “__del__" to come between “deleting…” and “done”. This is not being 
> > run from the interactive interpreter by via a .py file.
> 
> This suggests the presence of a reference cycle, since the object is deleted 
> afterward by the garbage collector. One cycle here is that the __del__ 
> function has a reference to the module's globals dict, which has a reference 
> to the class instance, which has a reference to the class, which has a 
> reference back to the function. There may be other cycles here as well, but 
> it may also be that the module object itself isn't part of them.
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Chris Angelico
On Mon, Nov 24, 2014 at 6:27 PM, Patrick Stinson  wrote:
> How does the __del__ method have a reference to the module’s globals dict?
> because it references the print function?
>
> Crazy. Is there any other way to comfort when a module is being deleted
> beside defining a class object with a printing dtor?

Functions have references to their modules. That's how they know what
globals to use.

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


Re: Python Logging and printf()

2014-11-24 Thread Ganesh Pal
Hi Chris,

Thanks for the comments , Iam planning to use logging handlers (
StreamHandler and FileHandler) to achieve my requirement .

Any quick reference example to this will be great , Iam on Python 2.7 , Iam
referring the python docs for mow.

Regards,
Ganesh

On Fri, Nov 21, 2014 at 5:25 PM, Chris Angelico  wrote:

> On Fri, Nov 21, 2014 at 9:48 PM, Ganesh Pal  wrote:
> > Please provide your input on the below questions.
> >
> > (1). How do i guarantee that  all console messages will be logged into
> the
> > logfile ?
> > (2) I feel the  need to retain few print(), how do I ensure the print()
> > messages are also logged into the log file.
>
> If you're using Python 3, you can shadow print() with your own
> function. The logging functions don't have the same signature, so
> you'd need to write a wrapper (or else stick to a strict policy of
> "one argument to print() and it must be a string"), but it's certainly
> possible.
>
> But part of the point of the logging module is that it's not the same
> as console messages: you can reduce log spam by changing the logging
> level. So no, you don't have a guarantee that all console messages
> will be logged to the log file. If you want that, I would suggest a
> process-level wrapper - something which invokes a subprocess with
> redirected stdout and/or stderr - or, at very least, a startup routine
> that does the redirection (which will have similar effect, except that
> it can't catch startup failure messages from Python itself).
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


A good Soap Client

2014-11-24 Thread Filadelfo Fiamma
Hi guys,
My question is about Soap Client for python.

Since 2011 I'm using the very good "Suds" library for consuming simple soap
service.
Now I need something for "SOAP over HTTPS", Does anyone know a good
solution? May I use suds and write an envelope for HTTPS?

Thanks in advance
Bye

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


Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-24 Thread Mark Lawrence

On 24/11/2014 06:25, Rick Johnson wrote:

On Sunday, November 23, 2014 4:37:53 PM UTC-6, Gregory Ewing wrote:

Chris Angelico wrote:

Just out of curiosity, why does the stdlib need modules
for manipulating .wav and other sound files, but we have
to go to PyPI to get a PostgreSQL client?


I suspect it's mainly for historical reasons. The wave
module has been around since the very early days of
Python when the stldib was smaller and the barrier
to entry was lower. By today's standards, it probably
wouldn't make it in.


Immigration policies evolve basically in the same manner.
When a country is founded in a land which is sparsely
populated, naturally the state will welcome any and all
immigrants (as noted in the "New Colossus"), but as the
population becomes more and more dense, the natural (and
wise) reaction is to limit, or even prohibit, the influx of
migrants.



The Native Americans are no doubt regretting their decision to "welcome 
any and all immigrants".  Would they have made the same decision using 
Python which obviously wouldn't have been available at that time?


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

Mark Lawrence

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Ned Batchelder

On 11/24/14 2:25 AM, Patrick Stinson wrote:

Basically, I have an app and am making it possible for the users to
automate it by writing python scripts that run against the app's API. It
includes PyQt5 widgets, a QScintilla editor, and a simple API for I/O.
Apple’s app store is the plan.

Right now I create a new module with types.ModuleType(‘something’), then
exec the code in the module’s dict. Then when the user saves the script
again in my editor, it deletes all top-level references in the module’s
dict that don’t belong to the core list: ['__spec__', '__name__',
'__loader__', '__package__', '__doc__', '__builtins__’] before running
exec again.

So far this seems to effectively “delete” the old module and re-compile
it with the updated source. For example I can create Qt Widgets on the
module level and they are safely deleted when the script is saved.



(BTW: the convention in most groups like this one is to bottom-post: put 
your responses beneath the text you are responding to.)


Keep in mind that Python object have a reference to their class. If your 
users are defining classes in their modules, and you instantiate the 
class to create objects, then even when you reload updated code, the old 
objects will still refer to the old classes.  This is one of the things 
that makes reloading modules in Python so difficult.





On Nov 23, 2014, at 5:56 PM, Ned Batchelder mailto:n...@nedbatchelder.com>> wrote:

On 11/23/14 1:49 AM, Patrick Stinson wrote:

If I create a module with imp.new_module(name), how can I unload it
so that all the references contained in it are set to zero and the
module is deleted? deleting the reference that is returned doesn’t
seem to do the job, and it’s not in sys.modules, so where is the
dangling reference?

Thanks!



This sounds tricky, and possible very difficult to do properly.  Do
you mind if I ask what the larger problem is?  Python might not be
very good at having modules come and go as you want.

--
Ned Batchelder, http://nedbatchelder.com

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







--
Ned Batchelder, http://nedbatchelder.com

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


PYTHON LOGGING with StreamHandler and FileHandler

2014-11-24 Thread Ganesh Pal
Hi Team,


The below program logs all the messages to the log file and displays the
same on the console .

Please suggest how do I ensure that error and warning log levels go ONLY to
stdout and/or stder


Code :

import logging
import sys

# StreamHandler
root = logging.getLogger()
root.setLevel(logging.DEBUG)

ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -
%(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)


# FileHandler

logger = logging.getLogger('myapp')
ch  = logging.FileHandler('/var/tmp/myapp1.log')
logger.setLevel(logging.DEBUG)

logger.error('We have a problem')
logger.info('While this is just chatty')
print "error abort" ## should be displayed on screen with using
loggin.

output :

# python  modified_logger.py
2014-11-24 11:18:12,355 - myapp - ERROR - We have a problem
2014-11-24 11:18:12,356 - myapp - INFO - While this is just chatty
error abort

# echo > /var/tmp/myapp1.log
# python  modified_logger.py
2014-11-24 11:18:45,872 - myapp - ERROR - We have a problem
2014-11-24 11:18:45,872 - myapp - INFO - While this is just chatty
error abort

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Ned Batchelder

On 11/23/14 5:10 AM, Patrick Stinson wrote:

I am defining a single class with a destructor method that prints
‘__del__’, and running that source code string using exec with the
module’s dict like so:

import rtmidi
importsys
import types
importtime
importgc

s= """
class A:
 def __del__(self):
 print('__del__')
a = A()
"""

m = types.ModuleType('mine')
exec(s, m.__dict__)
print('deleting...')
m= None
print('done')

and the output is:

deleting...
done
__del__

I the “__del__" to come between “deleting…” and “done”. This is not
being run from the interactive interpreter by via a .py file.



Let's look at this another way: Why do you need the module to be 
unloaded?  Isn't it enough to have the new code loaded?


--
Ned Batchelder, http://nedbatchelder.com

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Chris Angelico
On Mon, Nov 24, 2014 at 10:21 PM, Ned Batchelder  wrote:
> Keep in mind that Python object have a reference to their class. If your
> users are defining classes in their modules, and you instantiate the class
> to create objects, then even when you reload updated code, the old objects
> will still refer to the old classes.  This is one of the things that makes
> reloading modules in Python so difficult.

Yes, which is why I actually moved right away from that model, in two
projects that are built heavily around code reloading. In both cases,
code is all done as simple functions which run and then finish, and
everything returns as quickly as possible to a main back-end loop. All
persistent state is kept in code-free data structures, usually
key-based mappings of various sorts, with instantiable objects being
used only in places where it won't matter if they keep using the old
code.

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


Re: Python Signal/Slot + QThred code analysis

2014-11-24 Thread Juan Christian
Oh, and this code I made by myself, I didn't copy. That's why I want you
guys to see if everything is ok.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I have no class

2014-11-24 Thread Dan Sommers
On Mon, 24 Nov 2014 16:11:32 +1100, Chris Angelico wrote:

> On Mon, Nov 24, 2014 at 3:21 PM, Steven D'Aprano  wrote:
>> On Sun, 23 Nov 2014 09:02:57 -0800, Rustom Mody wrote:
>>
>>> Python is a bit odd in the OO-world in that it prioritizes "Explicit is
>>> better than implicit" over convenience.
>>>
>>> Notice that you use self.throw where in most other OOP languages you
>>> would use just throw.
>>
>> I don't think that is correct. I think that most OOP languages are like
>> Python, and use a special variable to reference the current instance:
>>
>> In some of these languages, the use of "this/self/me" is optional, but
>> I'm not aware of *any* OOP language where there is no named reference to
>> the current object at all.
> 
> I believe his point is that Python, unlike every other language he can
> think of, requires "self.x" instead of just "x". Every language needs
> a way to say "current object", but not every language needs you to say
> that for every member reference. C++, Pike, and Java let you
> short-hand that. (They're all deriving from the same syntactic style
> anyway.) JavaScript doesn't, I believe, although its variable scoping
> rules are some of the most insane I've ever met, so there might be a
> way to shortcut it. If your experience of OO is mainly from C++/Java
> family languages, then yes, Python will seem odd.

And then, at least in C++, you see coding standards that demand that
member variables (aka instance variables aka attributes) be named in
such a way that you can tell that they're member variables and not local
variables (one common convenstion is that all member variables begin
with "m_").  IMO, that's a concession that all that implicitness and
convenience just causes confusion.  In Python, the names of all instance
attributes begin with "self."

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


Re: I have no class

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 12:44 AM, Dan Sommers  wrote:
> And then, at least in C++, you see coding standards that demand that
> member variables (aka instance variables aka attributes) be named in
> such a way that you can tell that they're member variables and not local
> variables (one common convenstion is that all member variables begin
> with "m_").  IMO, that's a concession that all that implicitness and
> convenience just causes confusion.  In Python, the names of all instance
> attributes begin with "self."

Either that, or it's a concession that bureaucracy has no idea what
makes for good code. One or t'other.

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Ian Kelly
On Nov 24, 2014 1:27 AM, "Patrick Stinson"  wrote:
>
> How does the __del__ method have a reference to the module’s globals
dict? because it references the print function?

The module's dict becomes the __globals__ dict used by the function for
looking up globals and builtins.

> Crazy. Is there any other way to comfort when a module is being deleted
beside defining a class object with a printing dtor?

Modules don't strictly have to be ModuleType. You could substitute a class
with a __del__ method for the module itself for testing this. Be careful
with leaving this in your production code though, as the presence of
__del__ methods can interfere with garbage collection and are not advisable
prior to 3.4.

You can also test whether an object is still in memory by looking for it in
gc.get_objects() although be warned that is an expensive call.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI toolkit(s) status

2014-11-24 Thread Ian Kelly
On Nov 21, 2014 10:09 PM, "Michael Torrie"  wrote:
> I can't speak for wxWidgets, but when I last looked at it years ago it
> fairly reeked of MFC-style GUI programming with event tables instead of
> a nice, flexible signal/callback interface.  Has this changed?

I recall the C++ implementation uses or used event tables, although I'm not
up on the details. The Python bindings have always used callbacks however.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic asyncio usage

2014-11-24 Thread Benjamin Risher
On Wednesday, March 26, 2014 6:35:31 AM UTC-5, Piotr Husiatyński wrote:
> Hi,
> I have posted the same question to python-tutor list *, but I'm trying
> my luck here as advised.
> 
> I'm trying to get more familiar with asyncio library. Using python
> 3.4, I wrote simple echo server (see attachement for the code). I know
> that instead of using bare bone send/recv I could use some of the
> helper functions, but I want to start with the basics.
> 
> Using attached code, I can connect from multiple sources, but echo
> won't work for all clients. Also, please look at the `sendall` mehtod
> - I have to manually remove write callback, otherwise it will be
> called all the time. Any tips on solving this problem?
> 
> * https://mail.python.org/pipermail/tutor/2014-March/100679.html

Hello, 

I was wondering if you ever made progress with your asyncio project.  I'm 
currently digging around for examples and reference material and came across 
your post.

I'd be interested in any tips/gotchas/examples you'd be willing to provide as 
far as asyncio.  

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 2:12 AM, Ian Kelly  wrote:
>> Crazy. Is there any other way to comfort when a module is being deleted
>> beside defining a class object with a printing dtor?
>
> Modules don't strictly have to be ModuleType. You could substitute a class
> with a __del__ method for the module itself for testing this.

And based on the original description of exec'ing code into the
module's dictionary, the module is actually quite superfluous - just
exec the code into an empty dict and you'll get a similar result.

Though if you're doing a lot with code reloading, you may want to
consider a language with stronger support for it, like Pike. Python
can do it, but it's not really something most people do, so the
language and stdlib are generally built on the assumption that, once
loaded, code stays loaded.

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


Re: Basic asyncio usage

2014-11-24 Thread Marko Rauhamaa
Benjamin Risher :

> I was wondering if you ever made progress with your asyncio project.
> I'm currently digging around for examples and reference material and
> came across your post.
>
> I'd be interested in any tips/gotchas/examples you'd be willing to
> provide as far as asyncio.

Here's an implementation of the classic Dining Philosophers problem:

   http://pacujo.net/~marko/philosophers.py>

The main object of the example is to see how multiple inputs can be
multiplexed using asyncio.wait(FIRST_COMPLETED).


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


Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-24 Thread Rick Johnson
On Monday, November 24, 2014 4:35:13 AM UTC-6, Mark Lawrence wrote:
> The Native Americans are no doubt regretting their
> decision to "welcome any and all immigrants".  Would they
> have made the same decision using Python which obviously
> wouldn't have been available at that time?

FINDERS KEEPERS; LOSERS WEEPERS!

Contrary to your naive interpretation of history, the native
Americans did not *welcome* anyone. The demise of the native
american society is a direct result of sins they committed
against their *OWN* evolution -- dancing mindlessly around
camp fires and worshiping spirits and rocks is the path to
evolutionary abyss! On the other hand, the Europeans
recognized the potential of the land, *seized it*, and
created the most powerful nation this world has ever seen.

EVOLUTION LOVES A WINNER!

This universe does not give a flying fig for your individual
delusions, nor your collective societal delusions. Religion
and spiritualism are nothing more than coping mechanisms
fostered by "emotional feeble" minds who are incapable of
facing the grim realities of their own mortality! Both have
done more harm to human evolution and happiness than almost
anything else. I'm disgusted to a member of a species for
which a vast majority of my fellows have cast aside
intelligence for the mind numbing repetitive rituals and
idol worship of "shiny things" or the "maternal comfort" of
a "father/mother figure".

WHERE'S WALDO?

Where are the monuments or the vast civilizations of the
these natives? All we have today are a few arrowheads and
some clay pots. Is "pup tenting" and "bareback horse riding"
something to aspire to?  

WHERE ARE ALL ANIMAL RIGHTS ACTIVIST?

There is reason why they are called "natives", and it has
more to do with their lack of any "levels of organization"
and less to do with their birth- right. Native Americans
were a nomadic people, and they were not a nomadic people
simply because they enjoyed hauling their houses on their
backs every three months (actually, the women did most of the
hauling)

WHERE ARE ALL THE FEMINIST?

They were nomadic because they lacked the collective
intelligence to appreciate the intrinsic value of large
centralized civilizations, and as such, they were forced to
constantly chase the food sources.

A MIND IS A TERRIBLE THING TO WASTE!

Their failure to thrive is a direct result of choosing to
utilize every muscle in the body except for the most
important muscle of all, that is, the brain. Instead of
trying to live "with the earth", they should of been trying
to "exploit it". These resources exist for human
exploitation, not simply because we have been ordained by
some benevolent creature, no, but because long ago we won the
battle of intelligence against our rivals, and the spoils of
that war are the rights to exploit this earth, and all it's
inhabitants.

TO THE VICTOR GO THE SPOILS!

The native Americans lost the battle of evolution, and as a
result, they also forfeited the rights of historical
narrative. 

HISTORY IS WRITTEN BY THE WINNERS!

So go ahead and take your children on another scouting trip,
so they can build a tee-pee and cook Indian bread, and you
can tell them *fantastical* stories about how the Indians
lived in "harmony" with the earth, and you can all sing
"Kumbaya" to the strumming sounds of a guitar.

But at some point in their lives, maybe around the time you
"shatter their innocence" with the truth about "Santa Claus" and
the "Easter Bunny", you might want to also reveal to them
the results of a societal rejection of intelligence -- lest
they grow up and become like our dear friend Mark, who is
*still* writing "letters to Santa".

ALL I WANT FOR CHRISTMAS IS TO SURROUND BY INTELLIGENT BEINGS!


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


Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-24 Thread Ned Batchelder

On 11/24/14 11:51 AM, Rick Johnson wrote:

... lots of off-topic ranting ...


Everyone: as tempting as it is to respond, the best course of action 
will be to completely ignore Rick's rants.


Thanks,

--
Ned Batchelder, http://nedbatchelder.com

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


Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-24 Thread Robin Becker

On 24/11/2014 16:51, Rick Johnson wrote:

EVOLUTION LOVES A WINNER!


I think evolution actually requires losers. Clearly there are more extinct 
species, peoples, languages etc etc than there are existing ones so perhaps if 
evolution 'loves' anything it 'loves' a loser.

--
Robin Becker

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


Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-24 Thread Marko Rauhamaa
Rick Johnson :

> FINDERS KEEPERS; LOSERS WEEPERS!
>
> Contrary to your naive interpretation of history, the native
> Americans [...]

Was this rant at least produced by a Python generator?

Where's the StopIteration exception when you need one?


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


Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-24 Thread Rustom Mody
On Monday, November 24, 2014 10:38:52 PM UTC+5:30, Marko Rauhamaa wrote:
> Rick Johnson :
> 
> > FINDERS KEEPERS; LOSERS WEEPERS!
> >
> > Contrary to your naive interpretation of history, the native
> > Americans [...]
> 
> Was this rant at least produced by a Python generator?
> 
> Where's the StopIteration exception when you need one?

Real culprit is Ian who just segfaulted python with an infinite generator


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


Re: Help with Python Multiprocessing

2014-11-24 Thread sohcahtoa82
On Sunday, November 23, 2014 12:56:51 PM UTC-8, Anurag wrote:
> Hey Socha,
> Your solution works. But then, all my 3 workers are running in a single 
> command window. How do I make them run in three different command windows?

That, I don't know.  You would probably need to open a new command window with 
subprocess.Popen (The exact command line would depend on your operating system) 
and write your script to include a command line option to tell it which worker 
it is, but that starts to get really complex fast, especially if data needs to 
be passed between the worker and the main process.

Otherwise, I don't know if what you really want to do can be done.  You might 
be better off looking into creating an actual GUI.  Maybe have a window with 
three text boxes with each worker adding text to their own box?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Comprehension with two variables - explanation needed

2014-11-24 Thread Steven D'Aprano
Chris Angelico wrote:

> On Mon, Nov 24, 2014 at 3:42 PM, Steven D'Aprano 
> wrote:
>> Today dis() returns the above, tomorrow it may return:
>>
>>   0 LOAD_GLOBAL  0 (x)
>>   3 INCREMENT
>>   5 RETURN_VALUE
>>
>> (say), and the Python code remains the same even though the byte code is
>> different.
> 
> I hope not! The x in the original function was a local, not a global,

D'oh!

I mean, yes, that was a test to see if you were paying attention, and you
have passed! Well done.

*whistles nonchalantly*


-- 
Steven

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


Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-24 Thread Ian Kelly
On Nov 23, 2014 4:41 PM, "Gregory Ewing" 
wrote:
>
> Chris Angelico wrote:
>>
>> Just out of curiosity, why does the stdlib need modules for
>> manipulating .wav and other sound files, but we have to go to PyPI to
>> get a PostgreSQL client?
>
>
> I suspect it's mainly for historical reasons. The wave
> module has been around since the very early days of
> Python when the stldib was smaller and the barrier
> to entry was lower. By today's standards, it probably
> wouldn't make it in.

Size may also be a factor. The wave module is around 300 lines of Python
code and isn't growing. The typical dbapi module is probably a bit larger.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python 2.7 and unicode (one more time)

2014-11-24 Thread Steven D'Aprano
Marko Rauhamaa wrote:

>> Py3's byte strings are still strings, though.
> 
> Hm. I don't think so. In a plain English sense, maybe, but that kind of
> usage can lead to confusion.

Only if you are determined to confuse yourself.

People are quite capable of interpreting correctly sentences like:

"My friend Susan and I were talking about Jenny, and she said that she had
had a horrible fight with her boyfriend and was breaking up with him."

and despite the ambiguity correctly interpret who "she" and "her" refers to
each time. Compared to that, correctly understanding the mild complexity
of "string" is trivial.

In Python usage, "string" always refers to the `str` type, unless prefixed
with "byte", in which case it refers to the immutable byte-string type
(`str` in Python 2, `bytes` in Python 3.)

"Unicode string" always refers to the immutable Unicode string type
(`unicode` in Python 2, `str` in Python 3).

"Text string" is more ambiguous. Some people consider the prefix to be
redundant, e.g. "text string" always refers to `str`, while others consider
it to be in opposition to "byte string", i.e. to be a synonym for "Unicode
string".

In all cases apart from an explicit "byte string", the word "string" is
always used for the native array-of-characters type delimited by plain
quotation marks, as used for error messages, user prompts, etc., regardless
whether the implementation is an array of 8-bit bytes (as used by Python
2), or the full Unicode character set (as used by Python 3). So in
practice, provided you know which version of Python is being discussed,
there is never any genuine ambiguity when using the word "string" and no
excuse for confusion.


-- 
Steven

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


Re: python 2.7 and unicode (one more time)

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 9:56 AM, Steven D'Aprano
 wrote:
> In all cases apart from an explicit "byte string", the word "string" is
> always used for the native array-of-characters type delimited by plain
> quotation marks, as used for error messages, user prompts, etc., regardless
> whether the implementation is an array of 8-bit bytes (as used by Python
> 2), or the full Unicode character set (as used by Python 3). So in
> practice, provided you know which version of Python is being discussed,
> there is never any genuine ambiguity when using the word "string" and no
> excuse for confusion.

And frequently, even if you're talking about Py2/Py3 cross code,
there's still no ambiguity about the word "string": it means a
default-for-the-language string. The locale.setlocale() function
expects a string as its second parameter, for instance. (And
unfortunately, flatly refuses the other sort, whichever way around
that is.)

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


Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 5:44 AM, Dennis Lee Bieber
 wrote:
> On Mon, 24 Nov 2014 10:05:11 +0200, "Frank Millman" 
> declaimed the following:
>
>>I will explain why such a feature would have been useful for me.
>>
>>My accounting system handles multiple companies. I needed to figure out a
>>way to keep each one's data separate from the others.
>>
>>Originally I supported two databases - PostgreSQL and Sql Server. They both
>>have a concept called 'schemas', which handles my requirement elegantly -
>>each company's data is stored in its own schema.
>>
>
> We must have a different impression of what a "schema" consists of. As
> I learned it, the "schema" basically came down to the statements defining
> the form of the data, the rules (triggers) on it, and the relationships
> between data items. http://en.wikipedia.org/wiki/Database_schema
>
> By that definition, SQLite3 does support "schemas" (it's all the DDL
> statements used to create the database less the data itself -- which are
> DML). So does Firebird, MySQL, Access/JET

The sense here is one of qualified names. In DB2 and PostgreSQL, you
can create a database, and then within that, create schemas. You
choose a database when you connect, and then you can write code like
this:

select customer_name, invoice_date from accts.invoices join
crm.customers on (customer_id = crm.customers.id) where blah blah

The table names are qualified with their schema names. You can also
have a "default schema", which is the one used for unqualified table
names, which lets you pick one from a group of related data sets: for
example, Frank's accounting system would probably make use of that,
such that the code needn't care after startup. It'll just select a
default schema (or, in PostgreSQL, alter the search_path), and then
most of the code will just use unqualified names. Any data that's not
company-specific (maybe the application stores UI config data in the
database too) can be stored in a dedicated schema and referenced by
qualified name.

Technically, a table can be referred to as
database_name.schema_name.table_name (and then you can add
.column_name after that, but I have NEVER seen anyone use the full
four-parter!), but in PostgreSQL, the database_name, if present, must
be the one that you connected to. In MySQL, there these things that
are kinda databases and kinda schemas, are referred to by both names,
and in terms of data separation, primarily act like schemas. In
SQLite3, there are basically no schemas, AIUI, but you can use
databases to do something similar - with the originally-mentioned
limitation.

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


Loading Python 2.7

2014-11-24 Thread Seymore4Head
When I installed Python, I installed 2.7 and 3.4.  I am using XP.
I have been using Python 3 by just right clicking on a py file and
choose Edit with Idle.  That works just fine when I am using 3, but
since I also use 2.7 for practice from online courses I haven't
figured out how to use the interactive shell.

What I do when I need to run 2.7 code is to just save the file to my
Python 2.7 folder and run a command prompt.  I then just type the py
file.  That works but I am left with a dos prompt when the file
finishes.  I sometimes would like to be able to use the interactive
shell with a 2.7 file in memory.

I don't know how to do that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Comprehension with two variables - explanation needed

2014-11-24 Thread Dan Stromberg
On Sun, Nov 23, 2014 at 8:42 PM, Steven D'Aprano  wrote:
> On Sun, 23 Nov 2014 08:45:39 -0800, Rustom Mody wrote:
>> First a one-line solution in haskell
>>
>> sieve (p:xs)   =p:sieve [x | x <- xs, x `mod` p /= 0]
>
> Don't use that! That is a horribly inefficient way to generate primes.
>
> Mathematically, it is a version of Euler's Sieve. It is sometimes wrongly
> described as "Sieve of Eratosthenes", but that is wrong. Due to it's
> horrible performance, Melissa O'Neill calls this the "Sleight on
> Eratosthenes":

I don't read Haskell, but here's a Sieve (or at least I thought it was
a Sieve) and a few other prime-related things:
http://stromberg.dnsalias.org/~dstromberg/primes/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A good Soap Client

2014-11-24 Thread Cameron Simpson

On 24Nov2014 10:46, Filadelfo Fiamma  wrote:

My question is about Soap Client for python.
Since 2011 I'm using the very good "Suds" library for consuming simple soap
service.
Now I need something for "SOAP over HTTPS", Does anyone know a good
solution? May I use suds and write an envelope for HTTPS?


I wrote a daemon that uses SUDS. It just gets the endpoint URL from the WSDL 
file, and if that happens to be HTTPS, it uses HTTPS. I didn't have to do 
anything special for this. I did have to do some hacking to run HTTPS through a 
proxy, but that was more a urllib issue than a SUDS issue and hopefully 
irrelevant for you.


In short, it should Just Work.

Have you got some example code that illustrates it not working?

Cheers,
Cameron Simpson 

Knox's box is a 286. Fox in Socks does hacks and tricks
Knox's box is hard to fix.   To fix poor Knox's box for kicks.
   - David Mar ,
 as quoted by John Mackin 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Loading Python 2.7

2014-11-24 Thread Wiktor
On Mon, 24 Nov 2014 18:25:25 -0500, Seymore4Head wrote:

> What I do when I need to run 2.7 code is to just save the file to my
> Python 2.7 folder and run a command prompt.  I then just type the py
> file.  That works but I am left with a dos prompt when the file
> finishes.  I sometimes would like to be able to use the interactive
> shell with a 2.7 file in memory.
> 
> I don't know how to do that.

  Don't save it to your Python27 folder. Just "run command prompt" in
folder where your *.py file is located and type in there:
> py -2 -i name_of_file.py

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


Re: Python Signal/Slot + QThred code analysis

2014-11-24 Thread Michael Torrie
On 11/24/2014 06:25 AM, Juan Christian wrote:
> Oh, and this code I made by myself, I didn't copy. That's why I want you
> guys to see if everything is ok.

Looks alright. Does it work?
-- 
https://mail.python.org/mailman/listinfo/python-list


Ducktyping

2014-11-24 Thread Steven D'Aprano
https://pbs.twimg.com/media/B3Fvg-sCYAAkLSV.jpg


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


Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-24 Thread Frank Millman

"Dennis Lee Bieber"  wrote in message 
news:lrr67al6ppa852agu9rq2dstqtue17i...@4ax.com...
> On Mon, 24 Nov 2014 10:05:11 +0200, "Frank Millman" 
> declaimed the following:
>
>>
>>Originally I supported two databases - PostgreSQL and Sql Server. They 
>>both
>>have a concept called 'schemas', which handles my requirement elegantly -
>>each company's data is stored in its own schema.
>>
>
> We must have a different impression of what a "schema" consists of. As
> I learned it, the "schema" basically came down to the statements defining
> the form of the data, the rules (triggers) on it, and the relationships
> between data items. http://en.wikipedia.org/wiki/Database_schema
>

I also find it confusing. The same word is used by different RDBMS's to mean 
different things.

When using sqlite3 in interactive mode, you can enter '.tables' to list all 
tables in the database, and you can enter '.schema {table_name}' to view the 
original DDL statement used to create the table.

>From the PostgreSQL docs -

"""
A database contains one or more named schemas, which in turn contain tables. 
Schemas also contain other kinds of named objects, including data types, 
functions, and operators. The same object name can be used in different 
schemas without conflict; for example, both schema1 and myschema can contain 
tables named mytable. Unlike databases, schemas are not rigidly separated: a 
user can access objects in any of the schemas in the database he is 
connected to, if he has privileges to do so.
"""

>
> For a client-server database system, with ability to restrict access
> based upon user accounts/host address, there are a number of ways to
> address the separation.
>
> Either each user account (company) gets its own database in the server
> -- possibly using the same pre-packaged DML to define the tables/etc --  
> and
> one uses the access control system to prevent an account from even knowing
> there are other databases out there... Or... there is one set of tables
> (one database) containing data from all the companies -- wherein each 
> table
> has a field identifying the company, and ALL accesses to the data is via
> views that incorporate a select clause restricting the data to the current
> logged in company.
>

I find that schemas gives me the advantages of both without the 
disadvantages.

The disadvantage of using separate databases is that I want the flexibility 
to allow one company to access data from another company, under controlled 
conditions, specified by various parameters and permissions. It might be 
possible to accesss a remote database with some systems, I don't know, but 
schemas make it easy.

The disadvantage of using a single database, with a column specifying the 
company, is that I want the flexibility to manage different companies, with 
different data requirements, within the same system. A common database would 
result in a mish-mash of different tables, some of which only relate to one 
company or group of companies,  and other tables relate to others. Using 
schemas, I create one schema per company, which contains only the data 
relating to that company.

Frank



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


Re: python 2.7 and unicode (one more time)

2014-11-24 Thread Marko Rauhamaa
Steven D'Aprano :

> Marko Rauhamaa wrote:
>
>>> Py3's byte strings are still strings, though.
>> 
>> Hm. I don't think so. In a plain English sense, maybe, but that kind of
>> usage can lead to confusion.
>
> Only if you are determined to confuse yourself.
>
> {...]
>
> In Python usage, "string" always refers to the `str` type, unless
> prefixed with "byte", in which case it refers to the immutable
> byte-string type (`str` in Python 2, `bytes` in Python 3.)

You are saying what I'm saying.

Byte strings are *not* strings.

Prairie dogs are not dogs. No need to call dogs "domesticated dogs" to
tell them apart from "prairie dogs".


Marko


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


Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 4:31 PM, Frank Millman  wrote:
>
> "Dennis Lee Bieber"  wrote in message
> news:lrr67al6ppa852agu9rq2dstqtue17i...@4ax.com...
>> We must have a different impression of what a "schema" consists of. As
>> I learned it, the "schema" basically came down to the statements defining
>> the form of the data, the rules (triggers) on it, and the relationships
>> between data items. http://en.wikipedia.org/wiki/Database_schema
>>
>
> I also find it confusing. The same word is used by different RDBMS's to mean
> different things.

They're not entirely different; in both cases, your database schema
is, broadly speaking, the structure of your tables and the
relationships between them. Consider the "schema" to be the design
document that lays out your data. Then you have two derivative forms
of it: one is what's usually called DDL, and is executable statements;
the other derives from the concept that one schema represents one
logical dataset, so another schema would represent a different logical
dataset, so you have named schemas.

Since SQLite3 doesn't have the concept of named schemas, it uses
"schema" solely in the sense of DDL. The SQL spec (and therefore
PostgreSQL) uses it in both senses.

> I find that schemas gives me the advantages of both without the
> disadvantages.

Yep. So, use a real database, with better compliance to the spec :)
What you have is similar to what I've done in a number of different
database systems; schemas to separate related sets of tables into
namespaces, and other schemas to store global/shared data, all inside
a single database.

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


Re: A good Soap Client

2014-11-24 Thread dieter
Filadelfo Fiamma  writes:

> Since 2011 I'm using the very good "Suds" library for consuming simple soap
> service.
> Now I need something for "SOAP over HTTPS", Does anyone know a good
> solution? May I use suds and write an envelope for HTTPS?

I can enforce Camerons statement: "suds" simply uses "HTTPS",
when this protocol appears in the WSDL url or the port definitions
inside the WSDL.

Should you need special things (such as provide a client certificate
for the HTTPS connection), you can pass on a "transport" parameter
to the "suds.client.Client" constructor that handles those specialities.

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson

> On Nov 24, 2014, at 6:12 AM, Ian Kelly  wrote:
> 
> 
> On Nov 24, 2014 1:27 AM, "Patrick Stinson"  > wrote:
> >
> > How does the __del__ method have a reference to the module’s globals dict? 
> > because it references the print function?
> 
> The module's dict becomes the __globals__ dict used by the function for 
> looking up globals and builtins.
> 
Wow, that’s very helpful and good to know. Funny I never ran into that when 
doing this via an extensive CPython embedding project. Or maybe I ignored it.
> > Crazy. Is there any other way to comfort when a module is being deleted 
> > beside defining a class object with a printing dtor?
> 
> Modules don't strictly have to be ModuleType. You could substitute a class 
> with a __del__ method for the module itself for testing this. Be careful with 
> leaving this in your production code though, as the presence of __del__ 
> methods can interfere with garbage collection and are not advisable prior to 
> 3.4.
> 
> You can also test whether an object is still in memory by looking for it in 
> gc.get_objects() although be warned that is an expensive call.
> 
Interesting concept. One thing I am doing is allowing one script to import 
another by name. So in my gui I’ll have a panel for each script with a line 
edit to set the name, which then generates an appropriate slug. Is it still 
possible to import non-module objects? I guess this question is just for fun 
now :)


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

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


Re: PYTHON LOGGING with StreamHandler and FileHandler

2014-11-24 Thread dieter
Ganesh Pal  writes:

> The below program logs all the messages to the log file and displays the
> same on the console .
>
> Please suggest how do I ensure that error and warning log levels go ONLY to
> stdout and/or stder

You read the handler related documentation of the logging module.
When I remember right, you will find there a method allowing you
to control which message levels are handled by the the respective handler.

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


Re: Ducktyping

2014-11-24 Thread Rustom Mody
On Tuesday, November 25, 2014 10:08:28 AM UTC+5:30, Steven D'Aprano wrote:
> https://pbs.twimg.com/media/B3Fvg-sCYAAkLSV.jpg

:-)

I will use this in a class.
Now to hunt a cartoon for the opposite -- static/rigorous typing
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unloading a module created with imp.new_module

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 5:48 PM, Patrick Stinson  wrote:
> Is it still possible to import non-module objects? I guess this question is
> just for fun now :)

rosuav@sikorsky:~$ python3
Python 3.5.0a0 (default:23ab1197df0b, Nov 20 2014, 12:57:44)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.modules["hello"]=lambda s: print("Hello, %s!"%s)
>>> import hello
>>> hello("world")
Hello, world!
>>>

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


Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson

> On Nov 24, 2014, at 2:44 AM, Ned Batchelder  wrote:
> 
> On 11/23/14 5:10 AM, Patrick Stinson wrote:
>> I am defining a single class with a destructor method that prints
>> ‘__del__’, and running that source code string using exec with the
>> module’s dict like so:
>> 
>> import rtmidi
>> importsys
>> import types
>> importtime
>> importgc
>> 
>> s= """
>> class A:
>> def __del__(self):
>> print('__del__')
>> a = A()
>> """
>> 
>> m = types.ModuleType('mine')
>> exec(s, m.__dict__)
>> print('deleting...')
>> m= None
>> print('done')
>> 
>> and the output is:
>> 
>> deleting...
>> done
>> __del__
>> 
>> I the “__del__" to come between “deleting…” and “done”. This is not
>> being run from the interactive interpreter by via a .py file.
>> 
> 
> Let's look at this another way: Why do you need the module to be unloaded?  
> Isn't it enough to have the new code loaded?

I think that’s a good question. My original intention was to delete the module 
and everything contained in it since that’s what best matches what the user 
would expect by recompiling a script that they just created within this app. 
But the more I read and think, this purist perspective doesn’t make much sense.

The solution that I’ve come up with (which seems to be working really well so 
far), is to delete all objects in the module’s dict except the usual implicit 
objects (__import__, __name__, etc), then re-compile the code into the module’s 
dict. This even works well when I define QWidget gui objects, as they are 
hidden and deleted when the last reference goes away.

The main drawbacks for this approach are that the scripts exist in the same 
interpreter, and so can directly manipulate the app’s object hierarchy. But a 
user would have to go out of their way to do that so it’s their own fault if 
they break something :)

I would *love* to see code examples of how this sort of thing is done, where 
you write a GUI app in python that allows it’s users to write plugins for it in 
python using a built-in editor.

Thanks! Great thread


> 
> -- 
> Ned Batchelder, http://nedbatchelder.com 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list 
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Embedded python 'scripting engine' inside Python app

2014-11-24 Thread Patrick Stinson

> On Nov 23, 2014, at 4:57 AM, Chris Angelico  wrote:
> 
> On Mon, Nov 24, 2014 at 12:20 AM, Patrick Stinson  
> wrote:
>> I think this is the way I’ll take it, and for all the same reasons. The only 
>> way they can break it is if they really want to. I guess anything other 
>> Franken-apps would be interesting to hear about too. And I’ll still stick it 
>> on the app store.
>> 
> 
> (Please note, the convention on this list/newsgroup - as with most
> tech lists - is to put your text underneath what you're quoting -
> so-called "bottom-posting" or "interleaved" style.)
> 
> Yep. I got in some trouble for doing this at my last salaried
> employment, because the boss couldn't get his head around the idea
> that an XKCD 936-compliant password is secure enough for a code
> executor, and that the absence of a code executor makes debugging much
> harder. (In the end, I just renamed it to "calculator" so it wasn't so
> obvious, and left it there. Debugging is important.) In my open-source
> MUD client, Gypsum, there's a code executor built-in, which I use
> regularly as a simple calculator, and also to manipulate the program's
> internals. Some examples:
> 
>> /x 123+456*789
> 359907
>> /x asin(.5)*180/3.14159
> 30.253399374
>> /x "Test "*5 + "Haha"
> "Test Test Test Test Test Haha"
>> /x window.mainwindow.iconify()
> GTK2.Window
> (and the main window has just been minimized, aka iconified)

Thanks for the stories in this and the other thread. I love these interesting 
problems that push the limits :)


> 
> Basically, any expression that I type after "/x" will be parsed and
> executed as code. There's no sandboxing at all; it's executed in its
> own globals() and locals(), but if it wants to tinker with external
> state, it's free to do that. Since all the code is there for the user
> to peruse anyway, I don't distinguish between "this you may do" and
> "this you may not do", but instead between "this is pledged to be
> supported throughout this major version" and "this is undocumented,
> use at your own risk" - on the understanding that most of the latter
> category is actually pretty stable, and can happily be used anyway.
> 
> Interpreted languages tend to make this kind of thing fairly easy, and
> on the day you have a weird error that you can't figure out, you will
> be no end of glad you have this. No triggering a core dump and then
> doing a post-mortem, just examine state live, using the language's
> natural syntax.
> 
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Embedded python 'scripting engine' inside Python app

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 6:38 PM, Patrick Stinson  wrote:
> Thanks for the stories in this and the other thread. I love these interesting 
> problems that push the limits :)

I agree. How boring is life when we never push the limits!

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


Re: A good Soap Client

2014-11-24 Thread Filadelfo Fiamma
Thanks Cameron,Dieter! Sure I haven't understood how to pass and use the
certificate to the client. I thought to write a HTTPS client to extract the
clean SOAP envelope and then passing it to Suds. Just for info, the service
I need to consume It's the Italian Healthcare System for Medical Doctor.
Ciao!)
Il 25/nov/2014 07:46 "dieter"  ha scritto:

> Filadelfo Fiamma  writes:
>
> > Since 2011 I'm using the very good "Suds" library for consuming simple
> soap
> > service.
> > Now I need something for "SOAP over HTTPS", Does anyone know a good
> > solution? May I use suds and write an envelope for HTTPS?
>
> I can enforce Camerons statement: "suds" simply uses "HTTPS",
> when this protocol appears in the WSDL url or the port definitions
> inside the WSDL.
>
> Should you need special things (such as provide a client certificate
> for the HTTPS connection), you can pass on a "transport" parameter
> to the "suds.client.Client" constructor that handles those specialities.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list