class in c subclasses python classes, called in python

2010-11-25 Thread alex goretoy
I'm looking to create an application that uses c++ and python together.
Currently my application is all python. But need to obfuscate some of the
code. I am wanting to have c++ code so I can handle encryption with it and
other tasks. But first I need it to subclass some python class objects.
One task that I need to do is create a class in c++ that subclasses 3 python
classes and calls the base class constructor as super would call in python.

I need this in c++. How can I do this please?
class ABC(a,b,c):
def __init__(self, *args, **kwargs):
super(ABC, self).__init__(*args, **kwargs)

What I would like to know is how would I create a class in C or C++ that
would:
1. create a class that subclasses 2 or more python classes
2. initializes the subclassed classes by calling the contructors like
python's super would
3. import the class in python and call this class constructor with
ABC(*args, **kwargs)


is there a way to do this? Thanks in advance :)
Thank you,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


ssh browser? where?

2010-09-05 Thread alex goretoy
why not ssh browser traffic? why use SSL certificate authorities which can't
be trusted in the first place?
Is SSH not proven to be secure?

To this day I have not seen ssh module for say Apache web server, why not?

I understand this maybe wrong list to ask this question, but I love you guys
so much at python and I think your smart... :)

Thank you,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ssh browser? where?

2010-09-05 Thread alex goretoy
 If we were to use SSH on the web, which is certainly not the point of
SSH,
 we'd still need some kind of certificate authority to make the whole
system
 workable.

Yeah, you are correct. I thought about that after having posted these
questions. Even though it was SSH there still would be wiggle room for a
mitm.

I had a dream last night that my future employer was asking me what SSH was.
lol

I appreciate your response and making it clear as day.

Still though, I think there maybe something for testing here. I personally
verify and scope out my cert manually. Well for the sites I visit often. But
I understand not everyone will be likely to do this.

Thank you,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: running .py files on Linux

2010-04-26 Thread alex goretoy
make sure the tar, zip or package you downloaded isn't corrupt. verify it
with a md5sum and then extract it. just a thought.
Thank you,
-Alex Goretoy
http://launchpad.net/~a1g


On Mon, Apr 26, 2010 at 11:05 AM, Tingting HAN hihigh...@gmail.com wrote:

 Dear Officer,
 I downloaded a C code packet which contains many .py files. When I try to
 run these.py files on my computer with Linux system, for every .py file the
 following error occurs:

 hantingt...@tityro:~/Downloads/triMC3D/python$ python

 Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)

 [GCC 4.4.1] on linux2

 Type help, copyright, credits or license for more information.

 

 [4]+  Stopped python

 hantingt...@tityro:~/Downloads/triMC3D/python$ python test_detector.py

 Traceback (most recent call last):

   File test_detector.py, line 9, in module

 from tables import *

   File /usr/lib/python2.6/dist-packages/tables/__init__.py, line 76, in
 module

 from tables.file import File, openFile, copyFile

   File /usr/lib/python2.6/dist-packages/tables/file.py, line 44, in
 module

 from tables import hdf5Extension

   File hdf5Extension.pyx, line 11, in hdf5Extension

 ImportError: No module named utilsExtension
 I downloaded the .

 I sincerely hope you could give me some advice to solve the problem.

 --
 Best regards,
 HAN Tingting

 ETSI de Telecomunicación - office C-203-1
 Dpto. Ingeniería Electrónica
 Ciudad Universitaria s/n
 Madrid 28040,  Spain
 TEL: +34 65 232 4340


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


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


Re: Encryption source code with md5

2010-03-28 Thread alex goretoy
There's not many options when it comes to obfuscating python source. If you
even do find a way to obfuscate it. It won't take much to reverse it. That's
just how python works. Really I wouldn't even worry about looking for a way
to do this, reason behind that is that it's not difficult to reverse it.
This is not c,c++, php or java man/woman. Good luck.

Thank you,
-Alex Goretoy
http://launchpad.net/~a1g


On Sun, Mar 28, 2010 at 12:59 AM, catalinf...@gmail.com 
catalinf...@gmail.com wrote:

 Dear friends .

 I have two simple questions:
 It is possible to encrypt with md5 python source code?
 What option do I have to protect my python source code?

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

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


Re: execute bash builtins in python

2010-03-22 Thread alex goretoy
-005c7000 r-xp  08:06 199680
/usr/lib/libpixman-1.so.0.14.0
005c7000-005c9000 r--p 00043000 08:06 199680
/usr/lib/libpixman-1.so.0.14.0
005c9000-005ca000 rw-p 00045000 08:06 199680
/usr/lib/libpixman-1.so.0.14.0
005ca000-005e r-xp  08:06 199106
/usr/lib/libdirect-1.2.so.0.7.0

Thank you,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: execute bash builtins in python

2010-03-22 Thread alex goretoy
for the broken pipe error, perhaps theres a different way I can get shell
output other than using subprocess? I need the output of alias command into
a string and output of declare command into a string as well, I would like
to also avoid creating of a single liner script to make this happen if at
all possible

Thank you,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: execute bash builtins in python

2010-03-22 Thread alex goretoy
actually using the -i param in the command to subprocess doesn't seem to
work as well as setting PS1 to some garbage, it starts a new interactive
shell therein kicking me out of python. :/

Thank you,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: execute bash builtins in python

2010-03-21 Thread alex goretoy
Thank you for the great suggestions. Steve Holden that is a good one, I will
try to adapt my application to your suggestion. This way I don't have to
source .bashrc when it could do all that for me including other things that
it does in the background. Thank you so much.

Nobody, I was not aware of that shell arg thing, thank you.

Ipython is ok, but in this case I would have to force another dependency,
which I'm trying to keep those as low as possible for such a small
application. In fact, I'm gonna remove desktopcouch (couchdb) as one of the
deps in the next release of courtesyflush. Expect the next release sometime
late next week, if you interested in the app. find it on launchpad. :)
Enjoy.

Thank you,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: EURO GIRLS MISS EUROPE MISS FRENCH FRENCH PRETTY GIRLS SEXY FRENCH GIRLS on www.sexyandpretty-girls.blogspot.com SEXY RUSSIAN GIRLS SEXY GREEK GIRLS SEXY DUTCH GIRLS SEXY UK G

2010-03-20 Thread alex goretoy
what do i do to remove this crap? how do i moderate it?

why not gpg sign messages on python-list that way you know your authorized
to post and spammers will have one more vector to deal with, there in
stopping the not so leet
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: EURO GIRLS MISS EUROPE

2010-03-20 Thread alex goretoy
On Sat, Mar 20, 2010 at 1:37 PM, D'Arcy J.M. Cain da...@druid.net wrote:

 aybe it's time to stop gatewaying the newsgroup to the mailing list.
 As a test I have moved all Python posts from gmail.com with a
 Newsgroup header into


ok thx, I'm learning as I go along
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: execute bash builtins in python

2010-03-13 Thread alex goretoy
I found this to be even better; maybe someone will find this useful, who
knows.
just export PS1, duh
Popen([bash -c 'export PS1='python'; source
$HOME/.bashrc;alias'],shell=True,stdout=PIPE).stdout.read()

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


Re: execute bash builtins in python

2010-03-12 Thread alex goretoy
Steve thank you. The problem is that you can only run commands from Popen or
os.system and stuff. You cant run bash shell builtin commands for some
reason.

I was able to get this to work. What I did is call this:

Popen([bash -c 'source
$HOME/.bashrc;alias'],shell=True,stdout=PIPE).stdout.read()

and make sure you don't have a line like this in your .bashrc:
[ -z $PS1 ]  return

Another approach I came up with was to set aliases and functions as a
environment variable and access them with os.environ.

this is how I'm doing it.

export ALIASES=`alias|awk '{print $2}'|cut -d = -f 1|xargs`
export FUNCTIONS=`declare -F|awk '{print $3}'|xargs`

use this at the end or the .bashrc and then you can access defined aliases
and functions inside python with environ

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


execute bash builtins in python

2010-03-11 Thread alex goretoy
hi,
i'm trying to write a section of my program that needs to run bash builtin
alias and declare, i've googled and tried every type of example i could find
no to avail. this is what I've tried below and it doesn't work, is there a
way for me to execute a bah builin from python? what i need is to take alias
output and pipe it to another command with python and return the results to
a string or list.

 p1=Popen([alias],stdout=PIPE)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.6/subprocess.py, line 621, in __init__
errread, errwrite)
  File /usr/lib/python2.6/subprocess.py, line 1126, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

if i add shell=True i get empty string and no thins error message

 p1=Popen([alias],stdout=PIPE,shell=True)
 p1
subprocess.Popen object at 0xb7589a4c
 p1.stdout.read()
''

thank you,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datelib pythonification

2010-03-09 Thread alex goretoy

 DATE_TYPE = type(date.today())

def dates_diff(self, *targs):

   nargs = len(targs)

   if nargs == 0:

   return self.enddate - self.startdate

   if nargs == 1:

   arg = targs[0]

   if not isinstance(arg, (list, tuple)) or len(arg) != 2:

   raise Exception(

   single arg must be list or tuple of length 2)

   start, end = arg

   elif nargs == 2:

   start, end = targs

   else:

   raise Exception(expected 0,1, or 2 args; found %d % nargs)

   if isinstance(start, DATE_TYPE) and isinstance(end, DATE_TYPE):

   return end - start

   raise Exception(both values must be of type DATE_TYPE)


 HTH,


 John


This is awesome. Thank you for your contribution. I wasn't sure anyone was
gonna reply; just saw your reply, pardon my delay. I will make the changes
you suggested to other functions that apply in the lib as well(mimic that
style of coding). Make it so it raises exceptions instead of failing over
quietly(fallback to the __init__ passed args in other words).

Is There any other functions or methods that you would recommend be added to
the lib?

Any and all other suggestions are welcome. I love python and you guys are
practically helping me expand on my knowledge in this realm :)

I haven't touched it in a little bit so after I mess with it again I'll be
able to add more this thread/lib or whatever.

Thanks Again,
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datelib pythonification

2010-03-09 Thread alex goretoy
I have another quick question. What would be the best way to implement dates
length function?
or should i just leave that up to the user using the lib?
-Alex Goretoy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datelib pythonification

2010-03-09 Thread alex goretoy
 import datelib
 datelib.datelib().dates_list()
[datetime.date(2009, 3, 10), datetime.date(2009, 4, 10), datetime.date(2009,
5, 10), datetime.date(2009, 6, 10), datetime.date(2009, 7, 10),
datetime.date(2009, 8, 10), datetime.date(2009, 9, 10), datetime.date(2009,
10, 10), datetime.date(2009, 11, 10), datetime.date(2009, 12, 10),
datetime.date(2010, 1, 10), datetime.date(2010, 2, 10), datetime.date(2010,
3, 10)]
 len(datelib.datelib().dates_list())
13

I know i can do this and untested below:

function dates_len(*targs, **dargs)
return len(self.dates_list(*targs, **dargs))

Is this bloating the lib with unnecessary functions/methods?

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


Re: Starting Python from the terminal with no welcome message

2010-02-28 Thread alex goretoy
On Sun, Feb 28, 2010 at 5:23 PM, candide cand...@free.invalid wrote:

 Hi,

 Does exist some option I could send to the python interpreter during an
 interactive session in order to avoid the printing of the  introductory
 message just above the top prompt ?

 In my case, the welcome message is the following :

 Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
 [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
 Type help, copyright, credits or license for more information.



 gdb has such an option (the so-called quiet option).


 Compare this :

 $ gdb
 GNU gdb 6.8-debian
 Copyright (C) 2008 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later
 http://gnu.org/licenses/gpl.html
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.  Type show copying
 and show warranty for details.
 This GDB was configured as i486-linux-gnu.
 (gdb)

 with that

 $ gdb -q
 (gdb)


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


good idea, could be very useful. I don't think I recall seeing that option
in python.
+1

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


Re: Multiple console windows for a single program?

2010-02-28 Thread alex goretoy
On Sun, Feb 28, 2010 at 5:27 PM, Blake B bl...@randomresources.com wrote:

 Hello,

 I'm wanting to write a program with multiple objects, each in a thread.
 Both will be doing output (with the print statement) almost constantly, so
 I'd like to be able to separate their outputs. What I want to do is have a
 separate window for each. Is my only option to make my own console windows
 using TK or something?

 Thanks in advance,
 Blake B

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

 you can also use python-vte

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


Re: loop through each line in a text file

2010-02-26 Thread alex goretoy
I smell homework
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variable definition

2010-02-26 Thread alex goretoy
On Fri, Feb 26, 2010 at 6:22 PM, Alf P. Steinbach al...@start.no wrote:

 * Raphael Mayoraz:

 Hello,


 I'd like to define variables with some specific name that has a common
 prefix.
 Something like this:

 varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
 for key, value in varDic.iteritems():
   'myPrefix' + key = value

 I know this is illegal, but there must be a trick somewhere.


 In general you'll IMHO be better off with the variables as attributes of an
 object.

 If you want them to be modifiable then you can do

  class Whatever: pass

  myPrefix = Whatever()
  myPrefix.a = 'a'
  myPrefix.b = 'b'
  myPrefix.c = 'c'

 If you want them to be sort of constants (weasel words intentional) then
 you might do (Python 3.x)  --  disclaimer: off-the-cuff  I'm not sure if
 that function is called 'namedtuple' but I think you'll find it anyway  --

  import collections

  Color = namedtuple( Color, red green blue )
  myPrefix = Color( 'a', 'b', 'c' )


 Cheers  hth.,

 - Alf

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


you can use setattr to do your bidding for setting variable like this. That
is how I've been able to do it. Not sure if its the best solution, but it is
a solution. I just don't know how to use setattr without it being in a
class.

 class stuff(object):
...  def __init__(self):
...   pass
...  def duuit(self,abc):
...   for k,v in abc.items():
...setattr(self,prefix_%s%k,v)
...
 varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
 abc=stuff()
 abc.duuit(varDic)
 dir(abc)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', 'duuit', 'prefix_blue',
'prefix_green', 'prefix_red']


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


Re: Creating variables from dicts

2010-02-25 Thread alex goretoy
The problem i see with using globals() is that it can overwrite a previously
defined function or key within the global namespace, making the code
potentially dangerous and wild with exploits.

my $0.02

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


Re: Starting with Classes - basic problem

2010-02-22 Thread alex goretoy
you need to define init with two underscores, I've made that mistake myself
long long time ago :)

def __init__

not def _init_

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


Re: datelib pythonification

2010-02-20 Thread alex goretoy
hello all,
since I posted this last time, I've added a new function dates_diff and
modified the dates_dict function to set timedelta values returned by
dates_diff in the returned dict

def dates_dict(self,*targs,**dargs):

dates_dict() - takes params same as prefs()
returns dict key/value pair of formatted/calculated dates
key is a date, value is timedelta enddate-startdate


self.prefs(*targs,**dargs)
d={}
try:
if self.format!=:
d[self.startdate.strftime(self.format)]=self.dates_diff()
else:
d[self.startdate]=self.dates_diff()
except ValueError:
d[%s%self.startdate]=self.dates_diff()
while self.startdateself.enddate:
a=self.calc(*targs,**dargs)[0]
d[a]=self.dates_diff()
self.reset_dates()
return d
def dates_diff(self,*targs):

dates_diff - return timedelta difference between startdata and
enddate
takes nothing, a tuple, a list or 2 date objects as params
return enddate - startdate timedelta


start,end=(self.startdate,self.enddate)
if targs:
if(len(targs)==1):
if(type(targs[0])==type(()) or targs[0] == type([])):
if(len(targs[0])==2):
start,end=(targs[0][0],targs[0][1])
elif(len(targs)== 2):
if(type(targs[0])==type(date.today()) and targs[1] ==
type(date.today())):
start,end=(targs[0],targs[1])
return end-start

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


Re: Man Bites Python

2009-04-16 Thread alex goretoy
+1 Aahz

-Alex Goretoy
http://www.goretoy.com

Mitch Hedberghttp://www.brainyquote.com/quotes/authors/m/mitch_hedberg.html
- I drank some boiling water because I wanted to whistle.

On Thu, Apr 16, 2009 at 2:32 PM, Roy Hyunjin Han 
starsareblueandfara...@gmail.com wrote:

 Hahaha!

 On Thu, Apr 16, 2009 at 10:27 AM, Aahz a...@pythoncraft.com wrote:
  http://news.yahoo.com/s/nm/20090415/od_nm/us_python_odd_1/print
  --
  Aahz (a...@pythoncraft.com)   *
 http://www.pythoncraft.com/
 
  Why is this newsgroup different from all other newsgroups?
  --
  http://mail.python.org/mailman/listinfo/python-list
 
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: How to create a virtual serial port?

2009-04-11 Thread alex goretoy
A number of vendors (Keyspan, Belkin) make USB serial ports.  FWIW, I
use one here on this iMac and OS X with screen(1) and a null modem cable
to act as a serial console for a headless Linux box.

+1

-Alex Goretoy
http://www.goretoy.com

Norman Mailerhttp://www.brainyquote.com/quotes/authors/n/norman_mailer.html
- Writing books is the closest men ever come to childbearing.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A request (was: how to repeat function definitions less

2009-03-25 Thread alex goretoy
my messages are _not_ spam.
-Alex Goretoy
http://www.goretoy.com

Robert Benchley  - I have tried to know absolutely nothing about a great
many things, and I have succeeded fair...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda forms and scoping

2009-03-22 Thread alex goretoy
Sorry to have confused yall. What I meant was that you can do something like
this, where the fucntion isn't called until it is bount to () with the right
params

 def a():
... print inside a
...
 def b():
... print inside b
...
 def c(a,b):
... a()
... b()
...
 d={c:(a,b)}
 d[c][0]()
inside a
 d[c][1]()
inside b
 d[c(d[c][0],d[c][1])]
inside a
inside b
Traceback (most recent call last):
  File stdin, line 1, in module
KeyError: None

where function a and b are bound in function c

-Alex Goretoy
http://www.goretoy.com

Samuel Beckett  - Birth was the death of him.

On Sun, Mar 22, 2009 at 2:42 PM, R. David Murray rdmur...@bitdance.comwrote:

 Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
  En Fri, 20 Mar 2009 23:16:00 -0300, alex goretoy
  aleksandr.gore...@gmail.com escribió:
 
   i looks at lambdas as unbound functions(or super function), in the case
   above we create the functions in a list places it in memory unboud,
 once
   binding a call to the memory address space it returns the value
  
   it is basically same as doing this:
   def f():
   print f
  
   a=f #unbound function, same as rename function
   a() #bind call to address space
 
  Mmm, I don't quite understand what you said. lambda creates functions
 that
  aren't different than functions created by def: apart from the name,
  they're really the same thing.

 Oh, good, I'm not the only one for whom the above didn't make sense :)
 I feel a little less dense now.

  And if you imply that *where* you call a function does matter, it does
  not. A function carries its own local namespace, its own closure, and its
  global namespace. At call time, no additional binding is done (except
  parameters - arguments).
 
  (and the address space is always the one of the running process)

 I poked around in the API docs and experimented with func_closure and
 related attributes, and after bending my brain for a while I think I
 understand this.  The actual implementation of the closure is a single
 list of 'cell' objects which represent namespace slots in the nested
 scopes in which the closed-over function is defined.

 But the fact that it is a single list is an implementation detail, and
 the implementation is in fact carefully designed so that conceptually
 we can think of the closure as giving the function access to those
 nested-scope namespaces in almost(*) the same sense that it has a
 reference to the global and local namespaces.  That is, if what a name
 in _any_ of those namespaces points to is changed, then the closed-over
 function sees those changes.

 In this way, we understand the original example:  when defining a
 lambda having a 'free variable' (that is, one not defined in either the
 local or global scope) that was a name in the surrounding function's
 local namespace, the lambda is going to see any changes made by the
 surrounding function with regards to what that name points to.  Thus,
 the final value that the lambda uses is whatever the final value of the
 for loop variable was when the surrounding function finished executing.

 However, I think that a Python closure is not quite the same thing as a
 'computer science' closure, for the same reason that people coming from a
 language with variables-and-values as opposed to namespaces get confused
 when dealing with Python function call semantics.  Consider:


 http://en.wikipedia.org/wiki/Closure_(computer_science)http://en.wikipedia.org/wiki/Closure_%28computer_science%29

 That says that a closure can be used to provide a function with a private
 set of variables that persist from one invocation to the next, so that
 a value established in one call can be accessed in the next.  The last
 part of that sentence is not true in Python, since any assignment inside
 a function affects only the local (per-invocation) namespace or (given
 a global statement) the global namespace.  A function cannot change the
 thing pointed to by a name in the closure.  Only the outer function,
 for whom that name is in its local namespace, can do that.

 (*) That last sentence in the previous paragraph is why I said '_almost_
 the same sense' earlier: a function can modify what names point to in
 its local and global namespaces, but cannot modify what names point to
 in the closure namespace.

 Of course, we can produce the same _effect_ as a computer science closure
 in Python by using mutable objects...which is exactly parallel to the
 difference between passing mutable or immutable objects in a function
 call.

 --
 R. David Murray   http://www.bitdance.com

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

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


Re: Lambda forms and scoping

2009-03-22 Thread alex goretoy
I'm talking about in function c, where we bind the function call, kinda same
thing with lambdas too, exactly same

def func1(a):
return a
def func2(a=,b=0):
return %s has %d apples%(a,b)
def c(f1,f2,**kwargs):
print f2(kwargs['name'], f1(kwargs['apple'])) #bind call to function 1
and return from a bound function 2

bollox=42
 d={bollox: (c,(func1,func2)} # call c, which is bound, passing in func1
and func2 unbound, function pointer
 print d[bollox][0](func1,func2,name=fred flinstone,apple=bollox)
fred flinstone has 42 apples

-Alex Goretoy
http://www.goretoy.com

Fred Allen  - The first time I sang in the church choir; two hundred people
changed their religion.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda forms and scoping

2009-03-22 Thread alex goretoy

 Ah, so this is a terminology issue. I'd say that a and b are *called* in
 function c, not *bound*. I've never seen bind used in this sense before,
 but as Humpty Dumpty said to Alice:


i use the word expressively

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is python worth learning as a second language?

2009-03-21 Thread alex goretoy
  I've only read he subject and a few lines from other responses.
 
  yes, it is worth learning. I came from PHP to Python. It's very powerful
 and
  makes application development easier for me than in PHP and/or C#, but
 bash,
  well that depends on the type of bash. It has a lot of diffent ways you
 can
  use it too, so that adds to how powerful it is.

 IMHO, Bash is great for quick and dirty hacks, as a kind of simplified
 Perl. But when bash script grows too big, I would consider rewriting it in
 Python rather than Perl. But this is just my personal choice.

 Since we are already a little offtopic :-), did you see any speed
 difference between PHP and Python? I understand, that you are doing web
 devel in those two?


yes, I am doing web developemnt. At the moment I'm playing around with
GAE(google app engine), but later on I most likely will setup a django site
for my combined projects set, web frontend

You are right, bash is very good for simple quick and dirty hacks, but when
the script growns it's much better to just use python

I really can't say too much about speed increase or decrease, it really
depends on the site and how its built, what libs are used and how they are
loaded, same thing in PHP, It would be difficult for me to same anything on
speed because of that. I built a templated modulated cms in CodeIgniter(PHP
MVC), google it, It is a base for a templated system. using smarty and ci
templating syntax, although the smarty side of things makes it slower I
think. Also it is modulated, which breaks up your code into modules that you
can load on the page into a div with ajax, preferrably jquery but you can
use any framework for that too

I can go on forever

I maybe will recreate something like that in python, is a good idea, thx

GAE is pretty limiting, but I will try to hack it to do things for me
anyway.
maybe uploading my own libs and import those or upload python into the
project, not sure yet, thats why I may go with django


-Alex Goretoy
http://www.goretoy.com

Samuel Beckett  - Birth was the death of him.

On Sat, Mar 21, 2009 at 3:17 PM, Tomasz Rola rto...@ceti.com.pl wrote:

 On Sat, 21 Mar 2009, Aahz wrote:

  In article pine.lnx.4.64.0903210534130.6...@tau.ceti.pl,
  Tomasz Rola  rto...@ceti.com.pl wrote:
  On Sat, 20 Mar 2009, Aahz wrote:
  
   Taking C++ and turning it into a VM model does not exactly strike me
   as particularly good use of resources.
  
  It doesn't strike me either. But resources are not the only dimension of
  judging the language, you know.
 
  You misunderstand me: I was talking about the resources (people and
  money) used to create Java.

 Ah, I see now. From my perspective, it depends on how things ended. Since
 Java went into VB-like direction, I think I can agree. They have to go
 deeper and deeper into this... dead end (business decisions and the like).
 But it wasn't always looking as bad as now, so, you know, it is always
 easy to judge past, especially knowing that something was a failure. As I
 was reading about Java's prospects long ago, the use of people and money
 by Sun seemed like quite good way of spending resources (not best, but
 justified). In my opinion, it was the direction Java took somewhere around
 dot com burst that has really sinked it (namely, letting go of innovating
 aspect and pushing Java as, pardon the word, business-level solution).

  Java is yet another language with heavy static typing and an
  object-oriented focus.  What should have caused me to waste more time
  before dismissing it?

 Really, I don't know. From how you wrote it, seems you had not much need
 to investigate the subject. So, since you did not feel such need in the
 first place, it could be difficult to convince you.

 It really depends on what kind of programs you write (or are going to
 write). For me, there are some cases, when I would at least consider Java
 during design phase:

 1. Writing code that has to be, umh, mobile (not in a cell phone sense).
 Working on a network, sending code to other nodes. Special case - when
 this code has to do some computations, not heavy enough to justify using
 C, but still enough so that JIT is an advantage (even though JIT may not
 be available on every node type). And, of course, having a C compiler on
 every node is not always feasible. My favourites at the moment would be:

  - Scheme. PLT Scheme has JIT and is my current workhorse language. It is
 possible to find other Scheme flavors on almost any =32-bit cpu. Cons:
 all those flavors, albeit very similar and based on well defined common
 standard - to be frank, not so common anymore, but this is irrelevant -
 are still a bit different which can get problematic).

  - Java. Has JIT and is quite ubiquitous, from mainframes to cellphones.
 Cons: different Java flavors, EE, SE, MIDP... are quite different and
 their common subset is too simple for my taste.

  - Python. I like it more than Java, sometimes it is possible to use JIT.
 Still, the fact that I

Re: __init__ vs. __del__

2009-03-21 Thread alex goretoy
__init__ is the object construction(initialization) faze

__del__ is the object destruction faze, I think GC also happens, not sure

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is python worth learning as a second language?

2009-03-21 Thread alex goretoy
I think Python in general maybe slower than PHP(from what I read), but it is
still fast enough for my project needs

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is python worth learning as a second language?

2009-03-21 Thread alex goretoy
oh yeah, your welcome. I'm just leaning, so I'm glad to help someone else
learn as well.

-Alex Goretoy
http://www.goretoy.com




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


Re: Lambda forms and scoping

2009-03-20 Thread alex goretoy
i looks at lambdas as unbound functions(or super function), in the case
above we create the functions in a list places it in memory unboud, once
binding a call to the memory address space it returns the value

it is basically same as doing this:
def f():
print f

a=f #unbound function, same as rename function
a() #bind call to address space

hope this helps

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie: precision question

2009-03-20 Thread alex goretoy
I think you are looking for this:

 (math.pi - (math.sqrt(math.pi)))**2
1.8745410610157363


simple, multiplication and division have a higher precedence over addition
and subtraction

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is python worth learning as a second language?

2009-03-20 Thread alex goretoy
I've only read he subject and a few lines from other responses.

yes, it is worth learning. I came from PHP to Python. It's very powerful and
makes application development easier for me than in PHP and/or C#, but bash,
well that depends on the type of bash. It has a lot of diffent ways you can
use it too, so that adds to how powerful it is.

-Alex Goretoy
http://www.goretoy.com

Samuel Beckett  - Birth was the death of him.

2009/3/20 Tomasz Rola rto...@ceti.com.pl

 On Thu, 19 Mar 2009, Aahz wrote:

  --===0027953262==
 
  In article 49b58b35$0$3548$426a7...@news.free.fr,
  Bruno Desthuilliers  bdesth.quelquech...@free.quelquepart.fr wrote:
  Tomasz Rola a écrit :
  
   I may not be objective (tried Java, hated it after 6 years).
  
  Arf - only took me 6 months !-)
 
  That long?  It only took me six minutes.

 Guess what, there was a time when Java was looking quite promising.
 Especially in the field of distributed computing (which then meant not
 only high performance clusters). And computers were of more than one type,
 used other cpus than Intel, too.

 Maybe it's easier to ridicule Java now, when it has not met the
 expectations. But still, some people (better than I) have spent few
 years writing software and doing their research in Java. Sure, that was
 before Java had been nominated the common denominator of programming
 languages.

 Regards,
 Tomasz Rola

 --
 ** A C programmer asked whether computer had Buddha's nature.  **
 ** As the answer, master did rm -rif on the programmer's home**
 ** directory. And then the C programmer became enlightened...  **
 ** **
 ** Tomasz Rola  mailto:tomasz_r...@bigfoot.com **

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


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


Re: A request (was: how to repeat function definitions less

2009-03-16 Thread alex goretoy
sorry, I'll try to keep it cool
-Alex Goretoy
http://www.goretoy.com



On Mon, Mar 16, 2009 at 2:08 AM, Dennis Lee Bieber wlfr...@ix.netcom.comwrote:

 On Sun, 15 Mar 2009 23:18:54 -0500, alex goretoy
 aleksandr.gore...@gmail.com declaimed the following in
 gmane.comp.python.general:

  what is I just set
  colors: self.opt['arg_opts_options']['imp_colors']
 
  then they are both pointing to the same place, correct?
 
  -Alex Goretoy
  http://www.goretoy.com
 
 
Could you PLEASE learn to trim quoted material -- especially...
 
  On Sun, Mar 15, 2009 at 11:16 PM, alex goretoy
  aleksandr.gore...@gmail.comwrote:
 

 ... when replying to yourself!

This (the message I'm replying too) has just FIVE lines of new text,
 but has a 4KB binary signature, and logs in as 180 lines in my news
 client!

Many of your posts are actually exceeding the 500-line limit I've
 set in my client for down-load -- yet have nothing worthy of 500 lines!
 --
WulfraedDennis Lee Bieber   KD6MOG
wlfr...@ix.netcom.com   wulfr...@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff:   web-a...@bestiaria.com)
HTTP://www.bestiaria.com/

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

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


Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread alex goretoy

   print(10 + 20 % 7)
 a bug or a feature?

It is a feature
print ((10+20) % 7)

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question: How do I add elements to **kwargs in a function?

2009-03-16 Thread alex goretoy
I think you may need to do something like this in your code, this is what I
will be doing here shortly too

class peanutsdict(dict):
__slots__ = ['defaultZZz']
def __init__(self,default=None):
dict.__init(self)
self.default = default

def __getitem__(self,key):
if key in self:
return dict.__getitem__(self,key)
else:

return self.default

def get(self, key, *args):
if not args:
args = (self.default,)
return dict.get(self, key, *args)

def merge(self, other):
for key in other:
if key not in self:
self[key] = other[key]

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


cool things you can do with dict

2009-03-16 Thread alex goretoy
I though this was cool so I'd post about it, its one of the recipes

class peanutsdict(dict):
def __init__(self,default=None):
dict.__init__(self)
self.default = default

def __getitem__(self,key):
if key in self:
return dict.__getitem__(self,key)
else:

return self.default

def get(self, key, *args):
if not args:
args = (self.default,)
return dict.get(self, key, *args)

def merge(self, other):
for key in other:
if key not in self:
self[key] = other[key]

a=peanutsdict()
a.b=peanutsdict()
a.b.c=peanutsdict()
a.x=1
a.b.y=2
a.b.c.z=3

 print a
{}
 print a.__dict__
{'default': None, 'x': 1, 'b': {}}
 print a.b.__dict__
{'default': None, 'y': 2, 'c': {}}
 print a.b.c.__dict__
{'default': None, 'z': 3}
 print a.b.c.z
3
 print a.b.c
{}
 a.b.b=peanutsdict()
 class pdict(dict): pass
...
 a.b.b.a=pdict()
 a.b.b
{}
 a.b.b.__dict__
{'default': None, 'a': {}}
 a.b.b.__dict__['a']
{}
 a.b.b.__dict__['a'].x=4
 a.b.b.__dict__['a'].x
4
 a.b.b.a.x
4

Anyone else know anymore cool pieces of code?


-Alex Goretoy
http://www.goretoy.com

Jean Anouilh  - What you get free costs too much.
--
http://mail.python.org/mailman/listinfo/python-list


Re: having a function called after the constructor/__init__ is done

2009-03-16 Thread alex goretoy
__del__

I use it to close a mysql connection

-Alex Goretoy
http://www.goretoy.com

E. B. White  - Be obscure clearly.

On Mon, Mar 16, 2009 at 10:11 PM, thomas.han...@gmail.com 
thomas.han...@gmail.com wrote:

 Hi all,

 We've been breaking our heads over a good way of accomplishing an
 on_load event in our multitouch GUI frameowork PyMT.  We think we'd
 like to trigger an on_load event after a class is fully instantiated
 (or just a function call for simplicity, so you dont need to worry
 about our specific system).  This is so that if I make a subclass of
 some widget, I dont have to overwrite the __init__ method (use super,
 know the args, and pass them) everytime.  Maybe I just want to do some
 really basic stuff that doesn't really have anything to do with the
 parent class.

 Anyway.  My first attempt was to simply put a call to self.on_load at
 the end of the widget base class.  This doesn't work though, because,
 if I subclass it and do things after the call to super.__init__,
 on_load will be called before the constructor finishes (when the top
 most parent class __init__ finishes)

 We've sort of managed to achieve this by using a decorator that
 changes the __init__ function.  but even this doesnt seem like the
 best way to do this.  a) I now have to decorate every constructor i
 ever write. b) it seems impossible to make it so that it only happens
 once after the object is actually instantiated (since i have a
 decorator on all my constructors..each constructor in the inheritance
 line will call on_load once)

 Can I do something fancy with metaclasses here?  I think I could kind
 of do this by making all my classes use __new__, and then essentially
 use __init__ as what i want on_load to be...but that just seems really
 nasty and unpythonic.  not to speak about the confusion it would cause
 with people trying to figure out the library.

 So any ideas on how to get a function called on an object just after
 __init__ is done executing?
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
sweet, I've been wondering how those work. I've read some stuff about them
and still doesn't make sense to me. Why would I want to use itPlease
explain, thank you
-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 1:05 AM, Michele Simionato 
michele.simion...@gmail.com wrote:

 On Mar 15, 12:09 am, s...@pobox.com wrote:
  I'm doing this in my code, how to make it define all this functions
 for me
  with lambda, I've been up for a while and cant seem to figure it out,
 whats
  the most efficient way to do it? with lambda? how? thx
 
  def red(self,value,color='red',level='INFO'):
  self.write(value,color,level)
  def gold(self,value,color='gold',level='INFO'):
  self.write(value,color,level)
  ...

 The first thing coming to my mind is a class decorator:

 def addcolors(*colors):
def dec(cls):
for color in colors:
def col(self, value, color=color, level='INFO'):
 self.write(value, color, level)
 col.__name__ = color
setattr(cls, color, col)
return cls
return dec

 @addcolors('red', 'gold')
 class C(object):
def write(self, value, color, level):
pass

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

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


suggestion for python function calling

2009-03-15 Thread alex goretoy
hi i have a suggestion, surely this wont wonk, and is merely a suggestion to
aedd this type of syntax to python

This is an insperation from peps 318

 def foo(self):
 perform method operation
 foo = classmethod(foo)

 where it says perform mthod operation, why not have that be an actual
syntax?
having those words initialized as functions lists dict generators, etc...

 then you could do something like:

new_variable = function variable function variable

duck = if os.path.walk talk must _duck

or something to this nature and then you could either make it call functions
later

duck().().()
or
fuck(().())
or
something like that, I'mma go to sleep nowI think this way it might the
language even stonger, but who knows, what do you all think? Not trying to
make it like ruby, just more options to the interpreter, and syntax styles
-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: suggestion for python function calling

2009-03-15 Thread alex goretoy
basically

import os
def quacks(self,value):
return (1,0)[value]
_aduck=~/goose
duck = if os.path.exists quacks str(_aduck)
duck()()

or does this get in the way with some other pre-existing syntax
interpretation implementations?

-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 1:54 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 hi i have a suggestion, surely this wont wonk, and is merely a suggestion
 to aedd this type of syntax to python

 This is an insperation from peps 318

 def foo(self):
 perform method operation
 foo = classmethod(foo)

 where it says perform mthod operation, why not have that be an actual
 syntax?
 having those words initialized as functions lists dict generators, etc...

  then you could do something like:

 new_variable = function variable function variable

 duck = if os.path.walk talk must _duck

 or something to this nature and then you could either make it call
 functions later

 duck().().()
 or
 fuck(().())
 or
 something like that, I'mma go to sleep nowI think this way it might the
 language even stonger, but who knows, what do you all think? Not trying to
 make it like ruby, just more options to the interpreter, and syntax styles
 -Alex Goretoy
 http://www.goretoy.com


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


Re: suggestion for python function calling

2009-03-15 Thread alex goretoy
actually it would be more like

import os
def quacks(value):
return %s/%s%s% (os.environ[PWD],os.path.dirname(__file__),value)
_aduck=goose
duck = if is not os.path.exists quacks str(_aduck)


to perform the calls
duck()()

this would only with with functions that return something though, I
believe


-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 2:08 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 import os
 def quacks(self,value):
 return (1,0)[value]
 _aduck=~/goose
 duck = if os.path.exists quacks str(_aduck)
 duck()()

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


Re: suggestion for python function calling

2009-03-15 Thread alex goretoy
or use . (dot) where variable and () (parans) where function

duck()().
or
duck.().()
or
for long sentences
duck.[].()()...

using dot seperator or double dot separator for application where its
currently not being used, but for syntax errors
-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 2:15 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 actually it would be more like

 import os
 def quacks(value):
 return %s/%s%s% (os.environ[PWD],os.path.dirname(__file__),value)
 _aduck=goose
 duck = if is not os.path.exists quacks str(_aduck)


 to perform the calls
 duck()()

 this would only with with functions that return something though, I
 believe


 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 2:08 AM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 import os
 def quacks(self,value):
 return (1,0)[value]
 _aduck=~/goose
 duck = if os.path.exists quacks str(_aduck)
 duck()()



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


Re: suggestion for python function calling

2009-03-15 Thread alex goretoy
maybe this is like decorators
-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 2:20 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 or use . (dot) where variable and () (parans) where function

 duck()().
 or
 duck.().()
 or
 for long sentences
 duck.[].()()...

 using dot seperator or double dot separator for application where its
 currently not being used, but for syntax errors
 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 2:15 AM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 actually it would be more like

 import os
 def quacks(value):
 return %s/%s%s% (os.environ[PWD],os.path.dirname(__file__),value)
 _aduck=goose
 duck = if is not os.path.exists quacks str(_aduck)


 to perform the calls
 duck()()

 this would only with with functions that return something though, I
 believe


 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 2:08 AM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 import os
 def quacks(self,value):
 return (1,0)[value]
 _aduck=~/goose
 duck = if os.path.exists quacks str(_aduck)
 duck()()




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


Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
I will also actually need to nest it like so

d={
   site_name:[s,site,'

 sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],

options:{
src_name:[ss,src,source],
mod_name:['m',mod,'mods',module,modules],
}

-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 10:51 AM, MRAB goo...@mrabarnett.plus.com wrote:

 d={
site_name:[s,site,'sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],


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


Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
this means i have to check if d[i] is list or dict and iterate over
properties
-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 1:03 PM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 I will also actually need to nest it like so

 d={
site_name:[s,site,'

 sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],

 options:{
 src_name:[ss,src,source],
 mod_name:['m',mod,'mods',module,modules],
 }

 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 10:51 AM, MRAB goo...@mrabarnett.plus.com wrote:

 d={
site_name:[s,site,'sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],



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


Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
this is what I did to define all my color functions by color name, but I am
still going to need a good solution for args

#import functions by color name into current namespace
 for color in self.colors.keys():
 setattr(self, color,lambda x,y=color,z=INFO:
 self._hero(x,y,z) )


Thanks to all of you for helping me learn python

-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 1:05 PM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 this means i have to check if d[i] is list or dict and iterate over
 properties
 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 1:03 PM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 I will also actually need to nest it like so

 d={
site_name:[s,site,'

 sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],

 options:{
 src_name:[ss,src,source],
 mod_name:['m',mod,'mods',module,modules],
 }

 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 10:51 AM, MRAB goo...@mrabarnett.plus.comwrote:

 d={
site_name:[s,site,'sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],




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


Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
Michele I tried your way but I dont seem to have a good grasp on the concept
yet, will read up more

for now I think I will try to make it work same way as colors only with
decorator as def inside def instead of @, that doesn't make sense quite yet

-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 3:12 PM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 this is what I did to define all my color functions by color name, but I am
 still going to need a good solution for args

 #import functions by color name into current namespace
 for color in self.colors.keys():
 setattr(self, color,lambda x,y=color,z=INFO:
 self._hero(x,y,z) )


 Thanks to all of you for helping me learn python

 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 1:05 PM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 this means i have to check if d[i] is list or dict and iterate over
 properties
 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 1:03 PM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 I will also actually need to nest it like so

 d={
site_name:[s,site,'

 sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],

 options:{
 src_name:[ss,src,source],
 mod_name:['m',mod,'mods',module,modules],
 }

 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 10:51 AM, MRAB goo...@mrabarnett.plus.comwrote:

 d={
site_name:[s,site,'sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],





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


Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
this is the final result of the args i will be parsing for now

d={
site_name:[s,sn,site,'sites','site_name','site_names'],
jar_name:[j,jn,jar,'jars','jar_name','jar_names'],

file_name:[f,fn,'file','files','filename','filenames','file_name','file_names'],
verbose:[v,vv,vvv,'verbose','verbosity'],
flavors:[fff,flav,flavor,flavors],

final_funcs:[ff,finfun,'fin_fun',final_func,'final_funct',final_funcs,

'final_functs',final_function,final_functions],

download_files:[d,'df',down,'down_file','down_files',download,
downloads,'download_file','download_files'],

colors:[c,cl,col,colo,color,colors,'reaper','reapers'],
options:{
imp_src:['ss',src,source,sources],
imp_mod:['m',mod,'mods',module,modules],

imp_opt:['o',oo,opt,'opts',option,options],

imp_set:['s','ss',sss,set,setting,settings],

imp_files:[f,fn,'file','files','filename','filenames','file_name','file_names'],
imp_flavors:[fff,flav,flavor,flavors],

imp_funcs:[ff,finfun,'fin_fun',final_func,'final_funct',final_funcs,

'final_functs',final_function,final_functions],

imp_downloads:[d,'df',down,'down_file','down_files',download,

downloads,'download_file','download_files'],

imp_colors:[c,cl,col,colo,color,colors,'reaper','reapers'],

imp_properties:[p,prop,property,properties]

},
properties:[p,prop,property,properties]
}

pynutbutter will be really good soon, thx for your help :) I'm glad to be
doing this in python

-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 3:30 PM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 Michele I tried your way but I dont seem to have a good grasp on the
 concept yet, will read up more

 for now I think I will try to make it work same way as colors only with
 decorator as def inside def instead of @, that doesn't make sense quite yet

 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 3:12 PM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 this is what I did to define all my color functions by color name, but I
 am still going to need a good solution for args

 #import functions by color name into current namespace
 for color in self.colors.keys():
 setattr(self, color,lambda x,y=color,z=INFO:
 self._hero(x,y,z) )


 Thanks to all of you for helping me learn python

 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 1:05 PM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 this means i have to check if d[i] is list or dict and iterate over
 properties
 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 1:03 PM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 I will also actually need to nest it like so

 d={
site_name:[s,site,'

 sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],

 options:{
 src_name:[ss,src,source],
 mod_name:['m',mod,'mods',module,modules],
 }

 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 10:51 AM, MRAB goo...@mrabarnett.plus.comwrote:

 d={
site_name:[s,site,'sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],






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


Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
ok now for the final result, i decided to split options out to a separate
dict of lists, does this look right to every one, I currently have error
somewhere else in my code so can't test this right now, Is this a good
method to do this? or is there another option?

self.opt={}
self.opt['arg_opts_options']={
imp_src:['ss',src,source,sources],
imp_mod:['m',mod,'mods',module,modules],
imp_opt:['o',oo,opt,'opts',option,options],
imp_set:['s','ss',sss,set,setting,settings],

imp_files:[f,fn,'file','files','filename','filenames','file_name','file_names'],
imp_flavors:[fff,flav,flavor,flavors],

imp_funcs:[ff,finfun,'fin_fun',final_func,'final_funct',final_funcs,

'final_functs',final_function,final_functions],

imp_downloads:[d,'df',down,'down_file','down_files',download,

downloads,'download_file','download_files'],

imp_colors:[c,cl,col,colo,color,colors,'reaper','reapers'],
imp_properties:[p,prop,property,properties]
}
self.opt['arg_opts']={
site_name:[s,sn,site,'sites','site_name','site_names'],
jar_name:[j,jn,jar,'jars','jar_name','jar_names'],

file_name:[f,fn,'file','files','filename','filenames','file_name','file_names'],
verbose:[v,vv,vvv,'verbose','verbosity'],
flavors:[fff,flav,flavor,flavors],

final_funcs:[ff,finfun,'fin_fun',final_func,'final_funct',final_funcs,

'final_functs',final_function,final_functions],

download_files:[d,'df',down,'down_file','down_files',download,
downloads,'download_file','download_files'],

colors:[c,cl,col,colo,color,colors,'reaper','reapers'],
options:['o','opt','option',options],
properties:[p,prop,property,properties]
}

def main(self):
def _set_arg(a,b):
for k,v in self.opt['arg_opts']:

if a in v:
if a in [colors,flavors,'final_funcs']:
if b is not :
_b=b.split(',')
for c in range(len(_b)):
_c=_b[c].split(:)
if _c[1] is not :
setattr(self,
opt['properties']['flavors'][_c[0]], _c[1])
self.soc.debug(%s%(args +k+:
,self.opt['properties'][k]))
elif a is download_files:
if b is not :
if bool(b):
print (\nDOWNLOAD FILES,b)
self.opt['properties']['settings'][a] = 1
self.soc.debug( %s%(args +a+:
,self.opt['properties']['settings'][a]) )
if b.find(://)  -1:
_b=b.split(;)
if _b[1] is not :

self.opt['properties']['file_downloads'][_b[0]]=_b[1]
self.soc.debug( %s%(args
file_downloads: ,self.opt['properties']['file_downloads'][_b[0]]) )
elif a is options:
_b=b.split(,)
for c in range(len(_b)):
_c=_b[c].split(':')
for i,j in self.opt['arg_opts_options']:
if _c[0] in j:
if _c[1] is not :
self.opt['properties'][j] = _c[1]
self.soc.debug( %s%(args imp_src:
,self.opt['properties']['imp_src']) )
else:
if b is not :
setattr(self, opt['properties'][a], b)
self.soc.debug(%s%(args +k+:
,self.opt['properties'][k]))


for _argsi in range(len(.join(self.args).split('='))-1):
_args=self.args[_argsi].split(=)
print (printing A:,_args)
_set_arg(_arg[0],_arg[1])
-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 3:56 PM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 this is the final result of the args i will be parsing for now

 d={
 site_name:[s,sn,site,'sites','site_name','site_names'],
 jar_name:[j,jn,jar,'jars','jar_name','jar_names'],

 file_name:[f,fn,'file','files','filename','filenames','file_name','file_names'],
 verbose:[v,vv,vvv,'verbose','verbosity'],
 flavors:[fff,flav,flavor,flavors],

 final_funcs:[ff,finfun,'fin_fun',final_func,'final_funct',final_funcs,

 'final_functs',final_function,final_functions],

 download_files:[d,'df',down,'down_file','down_files',download,
 downloads,'download_file','download_files'],

 colors:[c,cl,col,colo,color,colors,'reaper','reapers'],
 options:{
 imp_src:['ss',src,source,sources],
 imp_mod:['m',mod,'mods

Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
i did this because this will read colors into a nested variable

How would i make this work the way you suggest? I already have it working
now :)

Not able to set to dict value with setattr, how to do this too(sorry if off
subject)?

I can set it like this:

for i in self.opt['properties'].keys():
self.opt[i] = getattr(self.opt['properties_object'],
i)
but not like this:
for i in self.opt['properties'].keys():
setattr(self, opt[i],
getattr(self.opt['properties_object'], i))
-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 6:41 PM, MRAB goo...@mrabarnett.plus.com wrote:

 alex goretoy wrote:

 ok now for the final result, i decided to split options out to a separate
 dict of lists, does this look right to every one, I currently have error
 somewhere else in my code so can't test this right now, Is this a good
 method to do this? or is there another option?

  [snip]
 First of all, *don't use is and is not to test for equality*; use ==
 and !=.

 When you split the options out like that you get duplication.

 You have, for example:

...
colors: [c, cl, col, ...]
...

 and:

...
imp_colors: [c, cl, col, ...]
...

 Couldn't you put them into one dict, something like:

   ...
   colors: (imp_colors, [c, cl, col, ...])
   ...


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

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


Re: how to repeat function definitions less

2009-03-15 Thread alex goretoy
what is I just set
colors: self.opt['arg_opts_options']['imp_colors']

then they are both pointing to the same place, correct?

-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 11:16 PM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 i did this because this will read colors into a nested variable

 How would i make this work the way you suggest? I already have it working
 now :)

 Not able to set to dict value with setattr, how to do this too(sorry if off
 subject)?

 I can set it like this:

 for i in self.opt['properties'].keys():
 self.opt[i] =
 getattr(self.opt['properties_object'], i)
 but not like this:
 for i in self.opt['properties'].keys():
 setattr(self, opt[i],
 getattr(self.opt['properties_object'], i))
 -Alex Goretoy
 http://www.goretoy.com



 On Sun, Mar 15, 2009 at 6:41 PM, MRAB goo...@mrabarnett.plus.com wrote:

 alex goretoy wrote:

 ok now for the final result, i decided to split options out to a separate
 dict of lists, does this look right to every one, I currently have error
 somewhere else in my code so can't test this right now, Is this a good
 method to do this? or is there another option?

  [snip]
 First of all, *don't use is and is not to test for equality*; use ==
 and !=.

 When you split the options out like that you get duplication.

 You have, for example:

...
colors: [c, cl, col, ...]
...

 and:

...
imp_colors: [c, cl, col, ...]
...

 Couldn't you put them into one dict, something like:

   ...
   colors: (imp_colors, [c, cl, col, ...])
   ...


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



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


Re: __import__ with dict values

2009-03-14 Thread alex goretoy

 I don't get *why* someone would like to write that. Does it look cool? Is
 it some kind of Look, ma, I know those hidden names! syndrome? Is it
 contagious?


I think thats what it is. It does look cool, thats for telling me about the
fact that

prevents the interpreter from doing many optimizations...

that makes sense to me, where would I read more about python optimizations?
I want to see code more, I like code, comments are good too :)

I have this piece of code I would like to turn into a generator, can some
one please help me do it?
I want to make it very optimized. The data comes from a options file that is
parsed and used for this header/field function mapping function . I need to
generate this, unless you advise against it then what are my options? How to
wrap my head around this?


def loop_lines(self):
self.soc.me_him(['ENTER:',__name__],self.func_me_color)
print self.lines
for k in range(len(self.lines)): #for every line in csv file
self.line=self.lines[k]
for optv in self.order:
for optvv in self._optv[optv][headers]:
if self._optv[optv][headers][optvv]!=:

_optvk=string.split(self._optv[optv][headers][optvv],,)
for optvk in _optvk:
for optvvv in self._optv[optv][mappings]:
if optvk == optvvv:
if
self._optv[optv][mappings][optvvv].find(self.fun.func) = 0:
self.field=optvvv

self.value=self.parsed[k][optvv].replace('', '\\').replace(', \\')

try:
exec
(self._optv[optv][mappings][optvvv]) #execute custom function
self.last_value=self.value
except NameError, e:
self.soc.w([\n\nERROR: %s
\n\nFUNCTION or VARIABLE IS DEFINED IN JAR_CONTROLLER % e],'white_on_red')
sys.exit(1)
#print self.opt['data']

#self.opt['data'][self.field]=self.fun.data[self.field]
#print self.opt['data']
else:
#self.soc.write([FUNC NOT
FOUND:,pfhpv[pfhpvi],self._pfmp[pfhpv[pfhpvi]]],'red')
#if self._pfmp[pfhpv[pfhpvi]]==
pfhp:

self.opt['data']['defaults'][optv][optvvv]=self.value
self.last_item=self.value
for ff in self.final_funcs.keys():
if self.final_funcs[ff]:
exec ( ff )

self.soc.me_him(['EXIT:',__name__],self.func_me_color)

Thank you,
-Alex Goretoy
http://www.goretoy.com



On Fri, Mar 13, 2009 at 11:56 PM, Gabriel Genellina
gagsl-...@yahoo.com.arwrote:

 prevents the interpreter from doing many optimizations...

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


Re: __import__ with dict values

2009-03-14 Thread alex goretoy
I'm actually still getting to this section of my code, I've been working a
logging,stdout colors lately, Although I am going to need __import__ in
several places in this program

-Alex Goretoy
http://www.goretoy.com



On Sat, Mar 14, 2009 at 3:05 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 I don't get *why* someone would like to write that. Does it look cool? Is
 it some kind of Look, ma, I know those hidden names! syndrome? Is it
 contagious?


 I think thats what it is. It does look cool, thats for telling me about the
 fact that

 prevents the interpreter from doing many optimizations...

 that makes sense to me, where would I read more about python optimizations?
 I want to see code more, I like code, comments are good too :)

 I have this piece of code I would like to turn into a generator, can some
 one please help me do it?
 I want to make it very optimized. The data comes from a options file that
 is parsed and used for this header/field function mapping function . I need
 to generate this, unless you advise against it then what are my options? How
 to wrap my head around this?


 def loop_lines(self):
 self.soc.me_him(['ENTER:',__name__],self.func_me_color)
 print self.lines
 for k in range(len(self.lines)): #for every line in csv file
 self.line=self.lines[k]
 for optv in self.order:
 for optvv in self._optv[optv][headers]:
 if self._optv[optv][headers][optvv]!=:

 _optvk=string.split(self._optv[optv][headers][optvv],,)
 for optvk in _optvk:
 for optvvv in self._optv[optv][mappings]:
 if optvk == optvvv:
 if
 self._optv[optv][mappings][optvvv].find(self.fun.func) = 0:
 self.field=optvvv

 self.value=self.parsed[k][optvv].replace('', '\\').replace(', \\')

 try:
 exec
 (self._optv[optv][mappings][optvvv]) #execute custom function
 self.last_value=self.value
 except NameError, e:
 self.soc.w([\n\nERROR: %s
 \n\nFUNCTION or VARIABLE IS DEFINED IN JAR_CONTROLLER % e],'white_on_red')
 sys.exit(1)
 #print self.opt['data']

 #self.opt['data'][self.field]=self.fun.data[self.field]
 #print self.opt['data']
 else:
 #self.soc.write([FUNC NOT
 FOUND:,pfhpv[pfhpvi],self._pfmp[pfhpv[pfhpvi]]],'red')
 #if self._pfmp[pfhpv[pfhpvi]]==
 pfhp:

 self.opt['data']['defaults'][optv][optvvv]=self.value
 self.last_item=self.value
 for ff in self.final_funcs.keys():
 if self.final_funcs[ff]:
 exec ( ff )

 self.soc.me_him(['EXIT:',__name__],self.func_me_color)

 Thank you,
 -Alex Goretoy
 http://www.goretoy.com



 On Fri, Mar 13, 2009 at 11:56 PM, Gabriel Genellina 
 gagsl-...@yahoo.com.ar wrote:

 prevents the interpreter from doing many optimizations...



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


Re: __import__ with dict values

2009-03-14 Thread alex goretoy
I can show you people more code if you want :) I like to learn
-Alex Goretoy
http://www.goretoy.com



On Sat, Mar 14, 2009 at 3:09 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 I'm actually still getting to this section of my code, I've been working a
 logging,stdout colors lately, Although I am going to need __import__ in
 several places in this program

 -Alex Goretoy
 http://www.goretoy.com



 On Sat, Mar 14, 2009 at 3:05 AM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 I don't get *why* someone would like to write that. Does it look cool?
 Is it some kind of Look, ma, I know those hidden names! syndrome? Is it
 contagious?


 I think thats what it is. It does look cool, thats for telling me about
 the fact that

 prevents the interpreter from doing many optimizations...

 that makes sense to me, where would I read more about python
 optimizations?
 I want to see code more, I like code, comments are good too :)

 I have this piece of code I would like to turn into a generator, can some
 one please help me do it?
 I want to make it very optimized. The data comes from a options file that
 is parsed and used for this header/field function mapping function . I need
 to generate this, unless you advise against it then what are my options? How
 to wrap my head around this?


 def loop_lines(self):
 self.soc.me_him(['ENTER:',__name__],self.func_me_color)
 print self.lines
 for k in range(len(self.lines)): #for every line in csv file
 self.line=self.lines[k]
 for optv in self.order:
 for optvv in self._optv[optv][headers]:
 if self._optv[optv][headers][optvv]!=:

 _optvk=string.split(self._optv[optv][headers][optvv],,)
 for optvk in _optvk:
 for optvvv in self._optv[optv][mappings]:
 if optvk == optvvv:
 if
 self._optv[optv][mappings][optvvv].find(self.fun.func) = 0:
 self.field=optvvv

 self.value=self.parsed[k][optvv].replace('', '\\').replace(', \\')

 try:
 exec
 (self._optv[optv][mappings][optvvv]) #execute custom function
 self.last_value=self.value
 except NameError, e:
 self.soc.w([\n\nERROR: %s
 \n\nFUNCTION or VARIABLE IS DEFINED IN JAR_CONTROLLER % e],'white_on_red')
 sys.exit(1)
 #print self.opt['data']

 #self.opt['data'][self.field]=self.fun.data[self.field]
 #print self.opt['data']
 else:
 #self.soc.write([FUNC NOT
 FOUND:,pfhpv[pfhpvi],self._pfmp[pfhpv[pfhpvi]]],'red')
 #if self._pfmp[pfhpv[pfhpvi]]==
 pfhp:

 self.opt['data']['defaults'][optv][optvvv]=self.value
 self.last_item=self.value
 for ff in self.final_funcs.keys():
 if self.final_funcs[ff]:
 exec ( ff )

 self.soc.me_him(['EXIT:',__name__],self.func_me_color)

 Thank you,
 -Alex Goretoy
 http://www.goretoy.com



 On Fri, Mar 13, 2009 at 11:56 PM, Gabriel Genellina 
 gagsl-...@yahoo.com.ar wrote:

 prevents the interpreter from doing many optimizations...




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


Re: __import__ with dict values

2009-03-14 Thread alex goretoy
This is a chunk of what its starting to look like now, thanks

from colors import _available_colors as _ck
from has_colors import _has_colors as _ha
from log import _brush as _er

class stdout_colors(object):
def
__init__(self,colors_active=1,output_caller=1,caller_color=red,default=1,
show_lineno_write=1,show_lineno_caller=1,break_all=1,
logging=1,log_type=INFO,depth=10):
self.caller_color = caller_color #stdout_colors function caller
called output color
self.output_caller = output_caller # output caller and called
function
self.colors_active = colors_active #active colors for output

self.colors = _ck().colors


crack=_er(colors_active,default,show_lineno_write,show_lineno_caller,
break_all,logging,log_type,depth)

#Thanks Gabriel Genellina, no crack was smoked during the making
#list( ( self.__setattr__(x.replace(b_,),getattr(B,x))  for x in
dir(B) if x.startswith(b_) ) )
for smoke in dir(crack):
if smoke.startswith(b_):
setattr(self, smoke[2:], getattr(crack, smoke))
-Alex Goretoy
http://www.goretoy.com



On Sat, Mar 14, 2009 at 3:13 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 I can show you people more code if you want :) I like to learn
 -Alex Goretoy
 http://www.goretoy.com



 On Sat, Mar 14, 2009 at 3:09 AM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 I'm actually still getting to this section of my code, I've been working a
 logging,stdout colors lately, Although I am going to need __import__ in
 several places in this program

 -Alex Goretoy
 http://www.goretoy.com



 On Sat, Mar 14, 2009 at 3:05 AM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 I don't get *why* someone would like to write that. Does it look cool?
 Is it some kind of Look, ma, I know those hidden names! syndrome? Is it
 contagious?


 I think thats what it is. It does look cool, thats for telling me about
 the fact that

 prevents the interpreter from doing many optimizations...

 that makes sense to me, where would I read more about python
 optimizations?
 I want to see code more, I like code, comments are good too :)

 I have this piece of code I would like to turn into a generator, can some
 one please help me do it?
 I want to make it very optimized. The data comes from a options file that
 is parsed and used for this header/field function mapping function . I need
 to generate this, unless you advise against it then what are my options? How
 to wrap my head around this?


 def loop_lines(self):
 self.soc.me_him(['ENTER:',__name__],self.func_me_color)
 print self.lines
 for k in range(len(self.lines)): #for every line in csv file
 self.line=self.lines[k]
 for optv in self.order:
 for optvv in self._optv[optv][headers]:
 if self._optv[optv][headers][optvv]!=:

 _optvk=string.split(self._optv[optv][headers][optvv],,)
 for optvk in _optvk:
 for optvvv in self._optv[optv][mappings]:
 if optvk == optvvv:
 if
 self._optv[optv][mappings][optvvv].find(self.fun.func) = 0:
 self.field=optvvv

 self.value=self.parsed[k][optvv].replace('', '\\').replace(', \\')

 try:
 exec
 (self._optv[optv][mappings][optvvv]) #execute custom function
 self.last_value=self.value
 except NameError, e:
 self.soc.w([\n\nERROR: %s
 \n\nFUNCTION or VARIABLE IS DEFINED IN JAR_CONTROLLER % e],'white_on_red')
 sys.exit(1)
 #print self.opt['data']

 #self.opt['data'][self.field]=self.fun.data[self.field]
 #print self.opt['data']
 else:
 #self.soc.write([FUNC NOT
 FOUND:,pfhpv[pfhpvi],self._pfmp[pfhpv[pfhpvi]]],'red')
 #if self._pfmp[pfhpv[pfhpvi]]==
 pfhp:

 self.opt['data']['defaults'][optv][optvvv]=self.value
 self.last_item=self.value
 for ff in self.final_funcs.keys():
 if self.final_funcs[ff]:
 exec ( ff )

 self.soc.me_him(['EXIT:',__name__],self.func_me_color)

 Thank you,
 -Alex Goretoy
 http://www.goretoy.com



 On Fri, Mar 13, 2009 at 11:56 PM, Gabriel Genellina 
 gagsl-...@yahoo.com.ar wrote:

 prevents the interpreter from doing many optimizations...





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


Re: converting a string to a function parameter

2009-03-14 Thread alex goretoy
My new class I've been working on might help you. It does what you are
asking without eval (I'm still working on it) Anyone have any ideas aswell
along with the OP, thank you

#!/usr/bin env python
#
# -*- coding: UTF-8 -*-
#
# PyNutButter BETA Version 0.1.0.1
#
# Copyright 2009 - Infinity by Alex Goretoy, All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Vinay Sajip
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# SEE ALSO LICENSE FILE IN PROJECT ROOT DIRECTORY
#
__author__  = Aleksandr Ilyich Goretoy agore...@gmail.com
__status__  = beta
__version__ = 0.1.0.1
__date__= 14 March 2009

import sys, os


from colors import colors as _ck
from has_colors import _has_colors as _ha
from logg import _brush as _ers

class colors(object):
def
__init__(self,colors_active=1,output_caller=1,caller_color=red,default=1,
show_lineno_write=1,show_lineno_caller=1,break_all=1,
logging=1,log_type=INFO,depth=10):

stdout colorization class - prints messages in color to stdout

colors_active - output to stdout in color? 1 or 0
output_caller - print output when control enters this
class/functions ,output caller and called function
caller_color - color to use to output caller only if output_caller
is 1


self.caller_color = caller_color #stdout_colors function caller
called output color
self.output_caller = output_caller # output caller and called
function
self.colors_active = colors_active #active colors for output

self.has_colors = _ha(sys.stdout)
self.colors = _ck
crack=_ers(logger=simpleExample,level=INFO,

log_file=log_file=os.environ[PWD]+/logs/eggo,spc=1,brk=1,slk=1,fn=1)

#Thanks Gabriel Genellina, no crack was smoked while making crack
like this
#list( ( self.__setattr__(x.replace(b_,),getattr(B,x))  for x in
dir(B) if x.startswith(b_) ) )
for smoke in dir(crack):
if smoke.startswith(b_):
setattr(self, smoke[2:], getattr(crack, smoke))


these colors may not be correct: depending on how you have your
terminal configured


#if self.output_caller:
#self.me_him(['ENTER COLORS',__name__],self.caller_color)



color and value

self.color=default#display color
self.value=#used to store displayed message


def w(self,value,color=red,level=INFO):
self.write(value,color,level)
def write(self,value,color=red,level=INFO):

write - output message,take value string or list,color=

self._hero(value,color,level)


def h(self,color=red,level=DEBUG):
self.him(color,level)
def him(self,color=red,level=DEBUG):

him - determines caller function name, takes color=


if self.output_caller:

value=sys._getframe(2).f_code.co_name#+inspect.currentframe().f_back.f_lineno
self._hero(value,color,level)

def m_h(self,value,color=purple,level=DEBUG):
self.me_him(value,color,level)
def me_him(self,value,color=purple,log_type=DEBUG):

me_him - determines current function prepends class name and
displays caller function

if self.output_caller:



value=.join(value)+.+sys._getframe(1).f_code.co_name+self.colors['default']+sys._getframe(2).f_code.co_name+\x1b[00m

self._hero(value,color,level)

def m(self,value,color=blue,level=DEBUG):
self.me(value,color,level)
def me(self,value,color=blue,level=DEBUG):

me - determines current function prepends class name, takes
value=__name__,color=

#self.frames()
value=.join(str(value)) + . +
.join(sys._getframe(1).f_code.co_name)
self._hero(value,color,level)

def _hero(self,value,color,level=INFO):
if self.colors_active:
try:
if self.colors[color] and self.has_colors != None:
self.reaper(value,self.colors[color],level)
self.spacer()
else:
self.reaper(value,self.colors

Re: converting a string to a function parameter

2009-03-14 Thread alex goretoy
This is a file that is going into the new version of python-stdout-colors

 project location:
 http://code.google.com/p/python-stdout-colors/


-Alex Goretoy
http://www.goretoy.com



On Sat, Mar 14, 2009 at 10:45 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 My new class I've been working on might help you. It does what you are
 asking without eval (I'm still working on it) Anyone have any ideas aswell
 along with the OP, thank you

 #!/usr/bin env python
 #
 # -*- coding: UTF-8 -*-
 #
 # PyNutButter BETA Version 0.1.0.1
 #
 # Copyright 2009 - Infinity by Alex Goretoy, All Rights Reserved.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose and without fee is hereby granted,
 # provided that the above copyright notice appear in all copies and that
 # both that copyright notice and this permission notice appear in
 # supporting documentation, and that the name of Vinay Sajip
 # not be used in advertising or publicity pertaining to distribution
 # of the software without specific, written prior permission.
 # VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 INCLUDING
 # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 # VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
 OR
 # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 WHETHER
 # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 OUT
 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
 # SEE ALSO LICENSE FILE IN PROJECT ROOT DIRECTORY
 #
 __author__  = Aleksandr Ilyich Goretoy agore...@gmail.com
 __status__  = beta
 __version__ = 0.1.0.1
 __date__= 14 March 2009

 import sys, os


 from colors import colors as _ck
 from has_colors import _has_colors as _ha
 from logg import _brush as _ers

 class colors(object):
 def
 __init__(self,colors_active=1,output_caller=1,caller_color=red,default=1,
 show_lineno_write=1,show_lineno_caller=1,break_all=1,
 logging=1,log_type=INFO,depth=10):
 
 stdout colorization class - prints messages in color to stdout

 colors_active - output to stdout in color? 1 or 0
 output_caller - print output when control enters this
 class/functions ,output caller and called function
 caller_color - color to use to output caller only if output_caller
 is 1
 

 self.caller_color = caller_color #stdout_colors function caller
 called output color
 self.output_caller = output_caller # output caller and called
 function
 self.colors_active = colors_active #active colors for output

 self.has_colors = _ha(sys.stdout)
 self.colors = _ck
 crack=_ers(logger=simpleExample,level=INFO,

 log_file=log_file=os.environ[PWD]+/logs/eggo,spc=1,brk=1,slk=1,fn=1)

 #Thanks Gabriel Genellina, no crack was smoked while making crack
 like this
 #list( ( self.__setattr__(x.replace(b_,),getattr(B,x))  for x
 in dir(B) if x.startswith(b_) ) )
 for smoke in dir(crack):
 if smoke.startswith(b_):
 setattr(self, smoke[2:], getattr(crack, smoke))

 
 these colors may not be correct: depending on how you have your
 terminal configured
 

 #if self.output_caller:
 #self.me_him(['ENTER COLORS',__name__],self.caller_color)


 
 color and value
 
 self.color=default#display color
 self.value=#used to store displayed message


 def w(self,value,color=red,level=INFO):
 self.write(value,color,level)
 def write(self,value,color=red,level=INFO):
 
 write - output message,take value string or list,color=
 
 self._hero(value,color,level)


 def h(self,color=red,level=DEBUG):
 self.him(color,level)
 def him(self,color=red,level=DEBUG):
 
 him - determines caller function name, takes color=
 

 if self.output_caller:

 value=sys._getframe(2).f_code.co_name#+inspect.currentframe().f_back.f_lineno
 self._hero(value,color,level)

 def m_h(self,value,color=purple,level=DEBUG):
 self.me_him(value,color,level)
 def me_him(self,value,color=purple,log_type=DEBUG):
 
 me_him - determines current function prepends class name and
 displays caller function
 
 if self.output_caller:



 value=.join(value)+.+sys._getframe(1).f_code.co_name+self.colors['default']+sys._getframe(2).f_code.co_name+\x1b[00m

 self._hero(value,color,level)

 def m(self,value,color=blue,level=DEBUG):
 self.me(value,color,level)
 def me(self,value,color=blue,level=DEBUG):
 
 me - determines current function prepends class name, takes
 value=__name__,color=
 
 #self.frames()
 value=.join(str(value)) + . +
 .join(sys._getframe(1

how to repeat function definitions less

2009-03-14 Thread alex goretoy
I'm doing this in my code, how to make it define all this functions for me
with lambda, I've been up for a while and cant seem to figure it out, whats
the most efficient way to do it? with lambda? how? thx

def red(self,value,color='red',level='INFO'):
self.write(value,color,level)
def gold(self,value,color='gold',level='INFO'):
self.write(value,color,level)
def green(self,value,color='green',level='INFO'):
self.write(value,color,level)
def blue(self,value,color='blue',level='INFO'):
self.write(value,color,level)
def yellow(self,value,color='yellow',level='INFO'):
self.write(value,color,level)
def purple(self,value,color='purple',level='INFO'):
self.write(value,color,level)
def w_red(self,value,color='white_on_red',level='INFO'):
self.write(value,color,level)
def w_gold(self,value,color='white_on_gold',level='INFO'):
self.write(value,color,level)
def w(self,value,color=red,level=INFO):
self.write(value,color,level)
def write(self,value,color=red,level=INFO):

write - output message,take value string or list,color=

self._hero(value,color,level)


-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to repeat function definitions less

2009-03-14 Thread alex goretoy
])
self.soc.debug( %s%(args imp_downloads:
,self.opt['properties']['imp_downloads']) )

-Alex Goretoy
http://www.goretoy.com



On Sat, Mar 14, 2009 at 6:54 PM, MRAB goo...@mrabarnett.plus.com wrote:


def write(self, value, color=red, level=INFO):
print value=%s, color=%s, level=%s % (repr(value), repr(color),
 repr(level))
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to repeat function definitions less

2009-03-14 Thread alex goretoy
I would imagine that I could do this with a generator and setattr, but I am
still learning how to do that kinda of codingmaybe if I had a dictionary
like this and then loaded it

d={
site_name:[s,site,'sites','site_name','site_names'],
jar_name:[j,jar,'jars','jar_name','jar_names'],
...
}

Once again, I haven't been sleeping regularly latelyworking on
pynutbutter 24/7...Thanks for all your help

-Alex Goretoy
http://www.goretoy.com



On Sat, Mar 14, 2009 at 10:02 PM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 Nice, this is good code. Thank you. Seeing as we are still on the same
 subject, how would I do it on sysarg values from getopt?

 I have a main method defined like so

 def main(self):
 #XXX
 
 1
 #get site_name: prepend to curl get/post requests
 #this overrides what it is in the jar

 2
 #get jar_name: jar_name used in directory for
 sys.path.append
 #import jar_name and loading jar_name.options and
 jar_name.settings
 #cmdline var o|options overrides default jar options and
 settings

 3
 #get file_name: parse this file for upload
 #this is optional, you can specify it in the jar options
 #overrides jar specified files to load. makes this the main
 file
 #only works with one file this way

 4
 #get verbose = 0:default 1:function/caller output 2:curl
 get/post requests/responses
 #this is optional, default is 0
 #still not working how it should, it's on the todo list

 5
 #flavors/butterknives to load with the jar, eg. mysql,
 curl, csvparser support
 #with plans for urllib, httplib,https, oracle, postgres,
 mssql
 #it is not hard to also add support for user defined custom
 protocols this way
 #then just define your mapped functions inside jar
 configuration directories
 #specifying this here option in the terminal overrides what
 is configured in the jar conf

 6
 #final functions to execute upon completion of all function
 mappings and exec for each line

 7
 #file to download and parse, this overrides disregards
 file_name if passed in simutaniously
 #to be used with remote files, located on http/s/ftp etc...
 it fetches the file and stores it
 #under the key() as the name, which is to be concurrent
 with keys in files, so that we know which is main
 #works with multiple files

 8
 #colors - allows you to specify what colors to use for
 output of caller/called functions, etc...

 9
 #specify source for options to be loaded from
 #you can specify custom option modules w/ attr  settings
 to load
 #todo: implement using options from db
 #todo: implement getting data from different sources other
 than csv files

 10
 #source of our configuration, only jars files work
 for now
 #currently default is storing configuration
 settings in jars files

 11
 # This is the jar conf file located in the jar
 directory
 #it is imported for getting
 options/settings/mappings/etc...
 #name of module to load which is located inside the
 jar dir

 12
 # jar configuration options attribute( dict that
 holds all mappings and functions, located in jar conf )
 # name of options dictionary that hold all jar
 options/mapping etc...

 13
 #jar configuration settings attribute (dict that
 holds all settings, located in jar conf file)
 #name of our settings dictionary that holds all jar
 settings

 14
 #jar file settings
 #secondary file to parse and use inside you
 functions

 
 for _argsi in range(len(.join(self.args).split('='))-1):
 _args=self.args[_argsi].split(=)
 print (printing A:,_args)
 #XXX#1
 if _args[0] in (s,site,'sites'):
 self.opt['properties']['site_name'] = _args[1]
 self.soc.debug( %s%(args site_name:
 ,self.opt['properties']['site_name']) )
 #XXX#2
 elif _args[0] in (j,jar,'jars','jar_name'):
 self.opt['properties']['jar_name'] = _args[1]
 self.soc.debug( %s%(args jar_name:
 ,self.opt['properties']['jar_name']) )

 #XXX#3
 elif _args[0] in
 (f,'file','files','filename','filenames','file_name','file_names'):
 self.opt['properties']['file_name'] = _args[1]
 self.soc.debug( %s%(args file_name

Re: __import__ with dict values

2009-03-13 Thread alex goretoy
wow, ok, thank you Gabriel, I wasn't aware of x,'y',z

This is what I decided to go with for now in one of my classes, but another
class will need a modified version of this, as mentioned x,'y',z

B=_brush()

list( ( self.__setattr__(x.replace(b_,),getattr(B,x))  for x in
dir(B) if x.startswith(b_) ) )



-Alex Goretoy
http://www.goretoy.com



On Fri, Mar 13, 2009 at 1:46 AM, Lie Ryan lie.1...@gmail.com wrote:

 Gabriel Genellina wrote:

 En Thu, 12 Mar 2009 09:27:35 -0200, alex goretoy 
 aleksandr.gore...@gmail.com escribió:

  note i would still like to be able to do __import__(sys).path


 p = __import__(sys).path

 That's a convoluted way of doing:

 import sys
 p = sys.path

 (except that the latter one inserts sys in the current namespace)


 That's a convoluted way of doing:

 from path import sys

 (except that the latter one doesn't insert sys in the current namespace)

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

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


__import__ with dict values

2009-03-12 Thread alex goretoy
How would I import with __import__ from dict values?
I want sys.path value inside d['syspath'], below code doesn't work for me


d={}
d['sys']='sys'
d['path']='path'

d['syspath']=__import__(d['sys'],fromlist=[d['path']])

and how come does  above line doesn't give me diff value than below line?

d['syspath']=__import__(d['sys'])

Meaning, when I do this doesn't work. Which makes sense.
d['syspath']()
d['syspath'].d['path']

but this works both with fromlist and without.

d['syspath'].path


-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: __import__ with dict values

2009-03-12 Thread alex goretoy
I have resolved this problem in my code. It has something to do with your
current working directory when you append cwd/jars to sys.path and try to
import from interactive console
-Alex Goretoy
http://www.goretoy.com



On Thu, Mar 12, 2009 at 4:58 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 How would I import with __import__ from dict values?
 I want sys.path value inside d['syspath'], below code doesn't work for me


 d={}
 d['sys']='sys'
 d['path']='path'

 d['syspath']=__import__(d['sys'],fromlist=[d['path']])

 and how come does  above line doesn't give me diff value than below line?

 d['syspath']=__import__(d['sys'])

 Meaning, when I do this doesn't work. Which makes sense.
 d['syspath']()
 d['syspath'].d['path']

 but this works both with fromlist and without.

 d['syspath'].path


 -Alex Goretoy
 http://www.goretoy.com


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


Re: __import__ with dict values

2009-03-12 Thread alex goretoy
yay, no more

exec (import  + sys)

in my code

-Alex Goretoy
http://www.goretoy.com



On Thu, Mar 12, 2009 at 5:42 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 I have resolved this problem in my code. It has something to do with your
 current working directory when you append cwd/jars to sys.path and try to
 import from interactive console
 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 4:58 AM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 How would I import with __import__ from dict values?
 I want sys.path value inside d['syspath'], below code doesn't work for me


 d={}
 d['sys']='sys'
 d['path']='path'

 d['syspath']=__import__(d['sys'],fromlist=[d['path']])

 and how come does  above line doesn't give me diff value than below line?

 d['syspath']=__import__(d['sys'])

 Meaning, when I do this doesn't work. Which makes sense.
 d['syspath']()
 d['syspath'].d['path']

 but this works both with fromlist and without.

 d['syspath'].path


 -Alex Goretoy
 http://www.goretoy.com



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


Re: __import__ with dict values

2009-03-12 Thread alex goretoy
or eval for that matter
-Alex Goretoy
http://www.goretoy.com



On Thu, Mar 12, 2009 at 5:43 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 yay, no more

 exec (import  + sys)

 in my code

 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 5:42 AM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 I have resolved this problem in my code. It has something to do with your
 current working directory when you append cwd/jars to sys.path and try to
 import from interactive console
 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 4:58 AM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 How would I import with __import__ from dict values?
 I want sys.path value inside d['syspath'], below code doesn't work for me


 d={}
 d['sys']='sys'
 d['path']='path'

 d['syspath']=__import__(d['sys'],fromlist=[d['path']])

 and how come does  above line doesn't give me diff value than below line?

 d['syspath']=__import__(d['sys'])

 Meaning, when I do this doesn't work. Which makes sense.
 d['syspath']()
 d['syspath'].d['path']

 but this works both with fromlist and without.

 d['syspath'].path


 -Alex Goretoy
 http://www.goretoy.com




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


Re: __import__ with dict values

2009-03-12 Thread alex goretoy
note i would still like to be able to do __import__(sys).path

maybe if __import__ had __str__ defined, How is my thinking on this?
and how would I achieve something like this?
-Alex Goretoy
http://www.goretoy.com



On Thu, Mar 12, 2009 at 5:44 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 or eval for that matter
 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 5:43 AM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 yay, no more

 exec (import  + sys)

 in my code

 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 5:42 AM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 I have resolved this problem in my code. It has something to do with your
 current working directory when you append cwd/jars to sys.path and try to
 import from interactive console
 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 4:58 AM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 How would I import with __import__ from dict values?
 I want sys.path value inside d['syspath'], below code doesn't work for
 me


 d={}
 d['sys']='sys'
 d['path']='path'

 d['syspath']=__import__(d['sys'],fromlist=[d['path']])

 and how come does  above line doesn't give me diff value than below
 line?

 d['syspath']=__import__(d['sys'])

 Meaning, when I do this doesn't work. Which makes sense.
 d['syspath']()
 d['syspath'].d['path']

 but this works both with fromlist and without.

 d['syspath'].path


 -Alex Goretoy
 http://www.goretoy.com





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


Re: __import__ with dict values

2009-03-12 Thread alex goretoy
__import__(opt['imp_mod']).options

eval(opt['imp_mod']+.+opt['imp_opt'])

how to make top work like bottom?
-Alex Goretoy
http://www.goretoy.com



On Thu, Mar 12, 2009 at 5:56 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 note i would still like to be able to do __import__(sys).path

 maybe if __import__ had __str__ defined, How is my thinking on this?
 and how would I achieve something like this?
 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 5:44 AM, alex goretoy aleksandr.gore...@gmail.com
  wrote:

 or eval for that matter
 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 5:43 AM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 yay, no more

 exec (import  + sys)

 in my code

 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 5:42 AM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 I have resolved this problem in my code. It has something to do with
 your current working directory when you append cwd/jars to sys.path and try
 to import from interactive console
 -Alex Goretoy
 http://www.goretoy.com



 On Thu, Mar 12, 2009 at 4:58 AM, alex goretoy 
 aleksandr.gore...@gmail.com wrote:

 How would I import with __import__ from dict values?
 I want sys.path value inside d['syspath'], below code doesn't work for
 me


 d={}
 d['sys']='sys'
 d['path']='path'

 d['syspath']=__import__(d['sys'],fromlist=[d['path']])

 and how come does  above line doesn't give me diff value than below
 line?

 d['syspath']=__import__(d['sys'])

 Meaning, when I do this doesn't work. Which makes sense.
 d['syspath']()
 d['syspath'].d['path']

 but this works both with fromlist and without.

 d['syspath'].path


 -Alex Goretoy
 http://www.goretoy.com






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


Re: __import__ with dict values

2009-03-12 Thread alex goretoy
Gabriel,

Thank you. This makes sense to me. I will go with sys.modules. Can you give
me a good example how to do it getattr way?

currently I am having this problem in my code. Kinda off subject, but not
entirely. I set default variable in self.opt after that I import
jar.properties into self.opt['properties']. Now my self.opt doesn't have the
same defaults set. in other words we load our configuration properties. Then
we over write any configuration properties with supplied sys.argv[1::]
arguments I am passing my sys.argv to a class and inside the class I use
getopt to get site_name and files_name, also many other variable that
overwrite the configuration that is set from the jar.properties

This was working when I was using exec and eval. I was not able to just use
exec I had to use exec on import and eval on module.module it was wierd, can
someone tell me why?

-Alex Goretoy
http://www.goretoy.com



On Thu, Mar 12, 2009 at 1:00 PM, Gabriel Genellina
gagsl-...@yahoo.com.arwrote:

 En Thu, 12 Mar 2009 09:27:35 -0200, alex goretoy 
 aleksandr.gore...@gmail.com escribió:

  note i would still like to be able to do __import__(sys).path


 p = __import__(sys).path

 That's a convoluted way of doing:

 import sys
 p = sys.path

 (except that the latter one inserts sys in the current namespace)

  maybe if __import__ had __str__ defined, How is my thinking on this?
 and how would I achieve something like this?


 __str__ has absolutely nothing to do.

  __import__(opt['imp_mod']).options

 eval(opt['imp_mod']+.+opt['imp_opt'])

 how to make top work like bottom?


 If you think you have to use eval: you don't. Never.

 module = __import__(opt['imp_mod'])
 module.options

 If the name options is not known until runtime, use getattr:

 getattr(module, name_of_attribute)

 The above assumes you want an attribute (like logging.ERROR). If you want a
 sub-module (a module inside a package) use __import__(dotted.name) and
 then retrieve the module by name from sys.modules; see
 http://docs.python.org/library/functions.html#__import__


 --
 Gabriel Genellina

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

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


[PyGTK] Singleton Window

2009-03-05 Thread alex goretoy
Hello All,

I am trying to create a singleton window in pygtk and for the life of me
can't seem to figure out a better way to go about doing this. The way I'm
doing it now is to recreate the window and show it. Example code is below. I
would much appreciate any assistance in this matter. I've googled to no
avail. I'm hiding the child window because when I execute main_quit on the
child it kills parent (which makes sense).

My singleton hack works, but its cluncky, I am wondering if theres some
other way(working shmingleton?).

My question is this. How to create a singleton child window without hiding
old childs(seeing as this creates many hidden childs after a while) or how
to hide it and when showing it again also have it display all contents in
the child window?

Thank you.

#!/usr/bin/env python
import os, sys

import pygtk
pygtk.require('2.0')
try:
  import gtk
except:
  print  sys.stderr, You need to install the python gtk bindings
  sys.exit(1)



class Singleton_Test(object):
  def __init__(self):
self.root_window = gtk.Window( type=gtk.WINDOW_TOPLEVEL )
self.root_window.set_title(Singleton Test)
self.root_window.connect(delete_event, lambda w,e: gtk.main_quit())

self.vbox = gtk.VBox(False,0)
self.root_window.add(self.vbox)
self.vbox.show()

self.singleton_button = gtk.Button(SINGLETON)
self.singleton_button.connect(clicked,self.singleton_cb)
self.vbox.pack_start(self.singleton_button,False,False,0)

self.singleton_button.show()

self.shmingleton_button = gtk.Button(SHMINGLETON)
self.shmingleton_button.connect(clicked,self.shmingleton_cb)
self.vbox.pack_start(self.shmingleton_button,False,False,0)

self.shmingleton_button.show()

self.create_singleton_child_window()

self.root_window.show()

  singleton_window_count=0
  def singleton_cb(self,w):
if self.singleton_window_count0:
  self.create_singleton_child_window()

self.singleton_child_window.show()
print singleton child window count is ,self.singleton_window_count
self.singleton_window_count+=1

  def shmingleton_cb(self,w):
self.singleton_child_window.show_all() #doesn't work as expected,
neither does show


  def create_singleton_child_window(self):
self.singleton_child_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.singleton_child_window.set_title(SINGLETON child)

#only hiding since gtk.main_quit kills parent, any better way?
self.singleton_child_window.connect(destroy, lambda w:
self.singleton_child_window.hide())
self.singleton_child_window.connect(delete_event, lambda w,e:
self.singleton_child_window.hide())

self.vbox = gtk.VBox(False, 0)
self.singleton_child_window.add(self.vbox)
self.vbox.show()
self.label = gtk.Label(SINGLETON)
self.vbox.pack_start(self.label,False,False,0)
self.label.show()

  def main(self):
gtk.main()

if __name__ == __main__:
  singleton = Singleton_Test()
  singleton.main()

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: [PyGTK] Singleton Window

2009-03-05 Thread alex goretoy
Correction, it's not True singleton.

-Alex Goretoy
http://www.goretoy.com



On Thu, Mar 5, 2009 at 10:38 PM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 Hello All,

 I am trying to create a singleton window in pygtk and for the life of me
 can't seem to figure out a better way to go about doing this. The way I'm
 doing it now is to recreate the window and show it. Example code is below. I
 would much appreciate any assistance in this matter. I've googled to no
 avail. I'm hiding the child window because when I execute main_quit on the
 child it kills parent (which makes sense).

 My singleton hack works, but its cluncky, I am wondering if theres some
 other way(working shmingleton?).

 My question is this. How to create a singleton child window without hiding
 old childs(seeing as this creates many hidden childs after a while) or how
 to hide it and when showing it again also have it display all contents in
 the child window?

 Thank you.

 #!/usr/bin/env python
 import os, sys

 import pygtk
 pygtk.require('2.0')
 try:
   import gtk
 except:
   print  sys.stderr, You need to install the python gtk bindings
   sys.exit(1)



 class Singleton_Test(object):
   def __init__(self):
 self.root_window = gtk.Window( type=gtk.WINDOW_TOPLEVEL )
 self.root_window.set_title(Singleton Test)
 self.root_window.connect(delete_event, lambda w,e: gtk.main_quit())

 self.vbox = gtk.VBox(False,0)
 self.root_window.add(self.vbox)
 self.vbox.show()

 self.singleton_button = gtk.Button(SINGLETON)
 self.singleton_button.connect(clicked,self.singleton_cb)
 self.vbox.pack_start(self.singleton_button,False,False,0)

 self.singleton_button.show()

 self.shmingleton_button = gtk.Button(SHMINGLETON)
 self.shmingleton_button.connect(clicked,self.shmingleton_cb)
 self.vbox.pack_start(self.shmingleton_button,False,False,0)

 self.shmingleton_button.show()

 self.create_singleton_child_window()

 self.root_window.show()

   singleton_window_count=0
   def singleton_cb(self,w):
 if self.singleton_window_count0:
   self.create_singleton_child_window()

 self.singleton_child_window.show()
 print singleton child window count is ,self.singleton_window_count
 self.singleton_window_count+=1

   def shmingleton_cb(self,w):
 self.singleton_child_window.show_all() #doesn't work as expected,
 neither does show


   def create_singleton_child_window(self):
 self.singleton_child_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 self.singleton_child_window.set_title(SINGLETON child)

 #only hiding since gtk.main_quit kills parent, any better way?
 self.singleton_child_window.connect(destroy, lambda w:
 self.singleton_child_window.hide())
 self.singleton_child_window.connect(delete_event, lambda w,e:
 self.singleton_child_window.hide())

 self.vbox = gtk.VBox(False, 0)
 self.singleton_child_window.add(self.vbox)
 self.vbox.show()
 self.label = gtk.Label(SINGLETON)
 self.vbox.pack_start(self.label,False,False,0)
 self.label.show()

   def main(self):
 gtk.main()

 if __name__ == __main__:
   singleton = Singleton_Test()
   singleton.main()

 -Alex Goretoy
 http://www.goretoy.com


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


Re: Explanation for trailing comma in example from Learning Python?

2009-02-19 Thread alex goretoy
Thank you for clerification Christian,
when using trailing comma with print statement/function, does it not mean to
output newline after printed data?

-Alex Goretoy
http://www.goretoy.com



On Thu, Feb 19, 2009 at 2:54 PM, Christian Heimes li...@cheimes.de wrote:

 Carl Schumann wrote:
  I could see the logic in always or never having a trailing comma.   What
  I don't understand here is why only the single element case has a
  trailing comma.   Any explanations please?

 Does this code shad some light on the trailing comma? :)

  (1) == 1
 True
  (1,) == 1
 False
  type((1))
 type 'int'
  type((1,))
 type 'tuple'

  a = 1
  a
 1
  a = (1)
  a
 1
  a = (1,)
  a
 (1,)
  a = 1,
  a
 (1,)

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

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


Re: Python Module for console text formatting?

2009-02-18 Thread alex goretoy
I created a little script for doing stdout coloring for me a while back.
Maybe this will get you closer to what you are looking for. It's kinda
hackish, but it works.

http://code.google.com/p/python-stdout-colors/

-Alex Goretoy
http://www.goretoy.com



On Wed, Feb 18, 2009 at 10:22 PM, srinivasan srinivas 
sri_anna...@yahoo.co.in wrote:

 Hi,
 Is it possible to apply more than one formatting to a string?
 For ex: the string 'test' has to be underlined and it should be bold. How
 to do that?

 Thanks,
 Srini
  --
 *From:* geremy condra c...@openmigration.net
 *To:* python-list@python.org
 *Sent:* Wednesday, 18 February, 2009 10:04:34 AM
 *Subject:* Re: Python Module for console text formatting?

 You can insert those codes just like you would any other character. If
 there's enough interest I can whip up a wrapper library for you.

 http://www.linux.gr/cgi-bin/man2html?console_codes+4

 On Tue, Feb 17, 2009 at 11:19 PM, srinivasan srinivas 
 sri_anna...@yahoo.co.in wrote:


 Hi,
 Does anyone know any python module other than 'ConsoleFormat0.1.1' used to
 format text on console?
 For example, printing bold characters on console.

 Thanks,
 Srini


  Did you know? You can CHAT without downloading messenger. Go to
 http://in.webmessenger.yahoo.com/
 --
 http://mail.python.org/mailman/listinfo/python-list




 --
 OpenMigration LLC- Open Source solutions for your business. Visit us at
 http://OpenMigration.net http://openmigration.net/.

 --
 Add more friends to your messenger and enjoy! Invite them 
 now.http://in.rd.yahoo.com/tagline_messenger_6/*http://messenger.yahoo.com/invite/

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


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


Re: best way to serve wsgi with multiple processes

2009-02-11 Thread alex goretoy
GAE (Google App Engine) uses WSGI for webapps. You don't have to overhead of
managing a server and all it's services this way as well. Just manage dns
entries. Although, there are limitations depending on your project needs of
what libs you need to use.

appengine.google.com

-Alex Goretoy
http://www.goretoy.com



On Wed, Feb 11, 2009 at 1:59 PM, Graham Dumpleton 
graham.dumple...@gmail.com wrote:

 On Feb 11, 8:50 pm, Robin robi...@gmail.com wrote:
  Hi,
 
  I am building some computational web services using soaplib. This
  creates a WSGI application.
 
  However, since some of these services are computationally intensive,
  and may be long running, I was looking for a way to use multiple
  processes. I thought about using multiprocessing.Process manually in
  the service, but I was a bit worried about how that might interact
  with a threaded server (I was hoping the thread serving that request
  could just wait until the child is finished). Also it would be good to
  keep the services as simple as possible so it's easier for people to
  write them.
 
  I have at the moment the following WSGI structure:
  TransLogger(URLMap(URLParser(soaplib objects)))
  although presumably, due to the beauty of WSGI, this shouldn't matter.
 
  As I've found with all web-related Python stuff, I'm overwhelmed by
  the choice and number of alternatives. I've so far been using cherrypy
  and ajp-wsgi for my testing, but am aware of Spawning, twisted etc.
  What would be the simplest [quickest to setup and fewest details of
  the server required - ideally with a simple example] and most reliable
  [this will eventually be 'in production' as part of a large scientific
  project] way to host this sort of WSGI with a process-per-request
  style?

 In this sort of situation one wouldn't normally do the work in the
 main web server, but have a separarte long running daemon process
 embedding mini web server that understands XML-RPC. The main web
 server would then make XML-RPC requests against the backend daemon
 process, which would use threading and or queueing to handle the
 requests.

 If the work is indeed long running, the backend process would normally
 just acknowledge the request and not wait. The web page would return
 and it would be up to user to then somehow occassionally poll web
 server, manually or by AJAX, to see how progres is going. That is,
 further XML-RPC requests from main server to backend daemon process
 asking about progress.

 I do't believe the suggestions about fastcgi/scgi/ajp/flup or mod_wsgi
 are really appropriate as you don't want this done in web server
 processes as then you are at mercy of web server processes being
 killed or dying when part way through something. Some of these systems
 will do this if requests take too long. Thus better to offload real
 work to another process.

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

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


Re: best way to serve wsgi with multiple processes

2009-02-11 Thread alex goretoy


 GAE is definitely not suitable in this case... The servers are
 provided and maintained as part of a large scientific project for
 which I am providing just a few services... Other groups are running
 services in other platforms on tomcat through soaplab/instantsoap -
 but I was hoping to use native python services since I thought it
 would be easier.


OK, that's cool. I understand about project requirements. It was just a
suggestion. Nonetheless I'm still interested in what people have to say in
this thread.
--
http://mail.python.org/mailman/listinfo/python-list


Re: GAE read binary file into db.BlobProperty()

2009-02-10 Thread alex goretoy
was not able to use open to open a binary file so what I did was use
urlfetch to fetch the image for me and read the content into BlobProperty()
Not sure why it took me so long to figure this out. Hope it helps someone.
thx

  def post(self,key):
k=db.get(key)
  img=images.Image(urlfetch.Fetch(http://www.example.com/
+k.image).content)
  img.rotate(90)
  jpg_data= img.execute_transforms(images.JPEG)
  k.image_blob=jpg_data
  k.put()

-Alex Goretoy
http://www.goretoy.com



On Mon, Feb 9, 2009 at 11:07 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 How to read Binary file into GAE(Google App Engine) db.BlobProperty()
 datastore?

 -Alex Goretoy
 http://www.goretoy.com


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


GAE read binary file into db.BlobProperty()

2009-02-09 Thread alex goretoy
How to read Binary file into GAE(Google App Engine) db.BlobProperty()
datastore?

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


GAE open()

2009-02-08 Thread alex goretoy
Hello,

How to open binary file for writing into datastore. I'm trying to loop over
listdir output of images directory, How to do this without using

self.request.POST.get.file.read(), or rather how to loop this task in app
engine

file(os.curdir+somefile).read()

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position
14: ordinal not in range(128)

but when I try to read binary with b, I get IOError.


raise IOError('invalid mode: %s' % mode)
IOError: invalid mode: b

-Alex Goretoy
http://www.alexgoretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Where to host a (Python) project?

2009-02-07 Thread alex goretoy
If you don't mind changing dns entries. You can also use Google App Engine.
It's really nice.

http://code.google.com/appengine/docs/python/tools/webapp/overview.html

-Alex Goretoy
http://www.alexgoretoy.com



On Fri, Feb 6, 2009 at 1:07 AM, alex goretoy aleksandr.gore...@gmail.comwrote:

 I use google code.
 http://code.google.com/p/pynutbutter

 -Alex Goretoy
 http://www.alexgoretoy.com




 On Thu, Feb 5, 2009 at 6:55 PM, Ben Finney 
 bignose+hates-s...@benfinney.id.au 
 bignose%2bhates-s...@benfinney.id.auwrote:

 a...@pythoncraft.com (Aahz) writes:

  In article 
 6dcb8ce5-c93e-458c-9047-e5db60f27...@v18g2000pro.googlegroups.com,
  andrew cooke  and...@acooke.org wrote:
  hi, just fyi, i investigated this and you can join any publicly
  readable group by sending an email to the -subscribe address. you
  do not need a google login for this and, as far as i can tell, it
  then operates for you like a normal mailing list.
 
  The same thing is theoretically true for Yahoo groups, but I've
  heard from people over the years about various difficulties fixing
  problems with list subscriptions in the absence of a real Yahoo
  login and I'm not particularly interested in finding out that the
  same thing ends up being true for Google lists.

 Indeed it does. I have succeeded in subscribing to Google mailing
 lists in the absence of a Google account, but *managing* that
 subscription thereafter in the absence of a Google account is
 obnoxiously difficult. Your caution is well advised.

 --
  \I got fired from my job the other day. They said my |
  `\  personality was weird. … That's okay, I have four more. |
 _o__)   —Bug-Eyed Earl, _Red Meat_ |
 Ben Finney
 --
 http://mail.python.org/mailman/listinfo/python-list



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


reconstruct html form in pyGTK window and create dict from pyGTK

2009-02-05 Thread alex goretoy
Hello All,

What would be the best way to fetch a form/s from a webpage and then
recreate it in a pygtk window?

I'm doing some research on this for a project called pynutbutter. This is
for jellpy actually, which handles creating option mappings for pynutbutter
from a GUI.
The things I know I would need some examples on:

How to work multiple glade files? (so i can have multiple pages for
different types of options) more efficient way, is this a good option?

loading of forms fields and reconstructiting in pyGTK with
comboboxes/comboboxtextentry textboxes/textentry and textviews, not how to
load them or display them...I can see that on pygtk websitebut the more
efficient way to do this dynamically.

What is the best way to create a dict from a gui? just have a user type the
dict: somedict={some:thing} or have another window pop up that handles for
name value pairs of the dict and a field for dict name.

After all this what would be the best way for me to merge this dict into a
options file. There will be other options in there. How would I only either
prepend the new dict or if one with same name exists overwrite it. Would
that be a safe move?

What would be the most effiecient and user friendly way to contruct this on
a form basis in a pyGTK GUI

defaults = {formfield:somevalue,anotherfield:somefieldvalue}
mappings =
{somefield:filefield1,anotherfield:some_function(filefield2)}
headers = {filefield1:somefield,filefield2:anotherfield}

What would be the best way for me to construct this dict from a user
friendly form in pyGTK

Sorry this is alot of questions. Any advise on this matter will be greatly
appreciated. Thank you.


-Alex Goretoy
http://www.alexgoretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Where to host a (Python) project?

2009-02-05 Thread alex goretoy
I use google code.
http://code.google.com/p/pynutbutter

-Alex Goretoy
http://www.alexgoretoy.com



On Thu, Feb 5, 2009 at 6:55 PM, Ben Finney 
bignose+hates-s...@benfinney.id.au bignose%2bhates-s...@benfinney.id.auwrote:

 a...@pythoncraft.com (Aahz) writes:

  In article 
 6dcb8ce5-c93e-458c-9047-e5db60f27...@v18g2000pro.googlegroups.com,
  andrew cooke  and...@acooke.org wrote:
  hi, just fyi, i investigated this and you can join any publicly
  readable group by sending an email to the -subscribe address. you
  do not need a google login for this and, as far as i can tell, it
  then operates for you like a normal mailing list.
 
  The same thing is theoretically true for Yahoo groups, but I've
  heard from people over the years about various difficulties fixing
  problems with list subscriptions in the absence of a real Yahoo
  login and I'm not particularly interested in finding out that the
  same thing ends up being true for Google lists.

 Indeed it does. I have succeeded in subscribing to Google mailing
 lists in the absence of a Google account, but *managing* that
 subscription thereafter in the absence of a Google account is
 obnoxiously difficult. Your caution is well advised.

 --
  \I got fired from my job the other day. They said my |
  `\  personality was weird. … That's okay, I have four more. |
 _o__)   —Bug-Eyed Earl, _Red Meat_ |
 Ben Finney
 --
 http://mail.python.org/mailman/listinfo/python-list

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


PyNutButter BETA 1.0.0 - Automates CSV data Importation into any website http/https and/or mysql database

2009-01-31 Thread alex goretoy
Introducing PynutButter BETA 1.0.0

Automates csv data importation into any website. Or your money back.
Programs like this idea of a program I have here cost $2500. Pynutbutter is
opensource. You can use the code anyway you want. As long as I get my credit
where it is due. I've worked on this project for roughly 1.5 years now. This
is an idea I tried in 2 languages. PHP and python, now.

No matter how much data in your csv file.
No matter what the field names are.
No matter how data is formatted

With PyNutButter you  can parse this data in custom functions and then send
it to its destinations.
You can map all the csv file headers to fields of a html page.
It loops for each line in the csv file and imports your data.

You must configure your configuration and create custom functions that you
can call from this configuration.

I've uploaded all the main files, except my configuration(I am working on
examples and making the main project page better)

You can find this project here:

http://code.google.com/p/pynutbutter/



I've worked long and hard on this application and the idea behind it. Any
help making this tool better would be greatly appreaciated.

Please let me know what you this of this tool. Any ideas/features are also
always welcome.

I also have a presentation I am working on for this tool. I hope to find a
nice job. This tools is very powerfuls. I was think next to try it with
scapy. That would be sweet. You can add custom flavors(data parsing/sending
libraries). My goal for this tool was to make everything as dynamic as
possible. calling of functions and dealing with parsed data in functions.
Only reason why I built is because I needed a tool like this. I know someone
else woulnd't mind having a tool like this either, so here you go. If you
can please donate or something somehow.

Upcoming Features:
use of parsed data from more than one file at a time.
pyGTK for ease of configuration creation(any help?)
gui creation of custom functions
automatic form parsing based on given urls in config

-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: ifconfig in python

2009-01-19 Thread alex goretoy
ifconfig -a|grep inet addr|awk '{print $2}'

wget http://myip.dk; cat index.html|grep div class=\Box\ rm
index.html*

this wget prolly better with urllib as prevoiusly noted by Дамјан, hope this
helps...

-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com


On Tue, Jan 20, 2009 at 3:42 AM, Дамјан Георгиевски gdam...@gmail.comwrote:

 Something *like*  this could work:

myip = 
 urllib2.urlopen('http://whatismyip.org/').read(http://whatismyip.org/%27%29.read%28
 )

 of course then you are depending on an external service, not a very
 reliable one even. But then again, you might create an internal service
 like that yourself.

 This cgi-bin shell code like this for ex:

 #! /bin/sh
 echo Content-type: text/plain
 echo
 echo ${REMOTE_ADDR}


 --
 дамјан ( http://softver.org.mk/damjan/ )

 Spammers scratch here with a diamond to find my address:
 |||
 --
 http://mail.python.org/mailman/listinfo/python-list

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


error: cannot invoke setopt() - perform() is currently running

2009-01-14 Thread alex goretoy
hello all,

I have a problem when using pycurl with threading Thread

from threading import Thread

the error i get is this:

error: cannot invoke setopt() - perform() is currently running


how do I catch a error like this in my code and perform a action like
wait for perform to finish until it tries to setopt again?

Has anyone come across this?

Any help in this matter will be highly appreciated, I've spent a week
on this and can't seem to figure it out. Googling hasn't brought me
any thing except my own codehahaha go figure TIA

-- 
-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: error: cannot invoke setopt() - perform() is currently running

2009-01-14 Thread alex goretoy
more info for all:

the class I'm trying to use threading on top of called pcrunchly. I've
posted it previously on here, but you can find it at this link.

http://article.gmane.org/gmane.comp.python.general/604050

How can i make this work with threading Thread?

On 1/15/09, alex goretoy aleksandr.gore...@gmail.com wrote:
 hello all,

 I have a problem when using pycurl with threading Thread

 from threading import Thread

 the error i get is this:

 error: cannot invoke setopt() - perform() is currently running


 how do I catch a error like this in my code and perform a action like
 wait for perform to finish until it tries to setopt again?

 Has anyone come across this?

 Any help in this matter will be highly appreciated, I've spent a week
 on this and can't seem to figure it out. Googling hasn't brought me
 any thing except my own codehahaha go figure TIA

 --
 -Alex Goretoy
 http://www.alexgoretoy.com
 somebodywhoca...@gmail.com



-- 
-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: error: cannot invoke setopt() - perform() is currently running

2009-01-14 Thread alex goretoy
sorry for multi posting It's a habit I have.

The closest thing I can come up with is this

http://pycurl.cvs.sourceforge.net/viewvc/pycurl/pycurl/examples/retriever-multi.py?revision=1.29view=markup

but how to make this work with pcrunchly and threading Thread?

On 1/15/09, alex goretoy aleksandr.gore...@gmail.com wrote:
 more info for all:

 the class I'm trying to use threading on top of called pcrunchly. I've
 posted it previously on here, but you can find it at this link.

 http://article.gmane.org/gmane.comp.python.general/604050

 How can i make this work with threading Thread?

 On 1/15/09, alex goretoy aleksandr.gore...@gmail.com wrote:
 hello all,

 I have a problem when using pycurl with threading Thread

 from threading import Thread

 the error i get is this:

 error: cannot invoke setopt() - perform() is currently running


 how do I catch a error like this in my code and perform a action like
 wait for perform to finish until it tries to setopt again?

 Has anyone come across this?

 Any help in this matter will be highly appreciated, I've spent a week
 on this and can't seem to figure it out. Googling hasn't brought me
 any thing except my own codehahaha go figure TIA

 --
 -Alex Goretoy
 http://www.alexgoretoy.com
 somebodywhoca...@gmail.com



 --
 -Alex Goretoy
 http://www.alexgoretoy.com
 somebodywhoca...@gmail.com



-- 
-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: File layout in development stage

2009-01-11 Thread alex goretoy
sys.path.append()

-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com


On Mon, Jan 12, 2009 at 2:00 AM, Steven Woody narkewo...@gmail.com wrote:

 Hi,

 Adapted your kindly suggestions in a previous post,  I now decide to
 organize my source tree in a pattern like below:


 prj:
src:
lib:
foomodule.py
barmodule.py
scripts:
prj_main.py
 test:
 footest.py
 bartest.py
 ...


 That is, I want to put the top-level scripts in  prj/src/scripts  and
 share libraries in prj/src/lib.  In the prj/test directory I want to
 put my unit-tests using unittest module.  My question is that when in
 development stage there is  no file is actually distributed, so how
 should a python source in one directory refer to (import) another
 module in another directory?

 Thanks in advance.

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

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


Re: urlopen exception

2009-01-10 Thread alex goretoy
I would try:

site=http://www.bput.org/;
payloads=scriptalert('xss')/script
attack= urllib2.urlopen(site+payloads,80).readlines()


-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com


On Sun, Jan 11, 2009 at 2:49 AM, Steve Holden st...@holdenweb.com wrote:

 Paul Rubin wrote:
  asit lipu...@gmail.com writes:
  site=www.bput.org
  payloads=scriptalert('xss')/script
  attack= urllib2.urlopen(site+payloads,80).readlines()
 
  according to my best knowledge, the above code is correct.
  but why it throws exceptio 
 
  The code is incorrect.  Look at the string ou are sending into
  urlopen.  What on earth are you trying to do?

 He's investigating potential cross-site scripting vulnerabilities.

 regards
  Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC  http://www.holdenweb.com/

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

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


Re: urlopen exception

2009-01-10 Thread alex goretoy
 oops, remove the ,80 since port is not needed. Well, in my case it wasn't
working with port. notice it gives me 404, but this with my domain

 att=urllib2.urlopen(site+payload,80).readlines()
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/local/lib/python2.6/urllib2.py, line 124, in urlopen
return _opener.open(url, data, timeout)
  File /usr/local/lib/python2.6/urllib2.py, line 381, in open
req = meth(req)
  File /usr/local/lib/python2.6/urllib2.py, line 1057, in do_request_
'Content-length', '%d' % len(data))
TypeError: object of type 'int' has no len()

 att=urllib2.urlopen(site+payload).readlines()
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/local/lib/python2.6/urllib2.py, line 124, in urlopen
return _opener.open(url, data, timeout)
  File /usr/local/lib/python2.6/urllib2.py, line 389, in open
response = meth(req, response)
  File /usr/local/lib/python2.6/urllib2.py, line 502, in http_response
'http', request, response, code, msg, hdrs)
  File /usr/local/lib/python2.6/urllib2.py, line 427, in error
return self._call_chain(*args)
  File /usr/local/lib/python2.6/urllib2.py, line 361, in _call_chain
result = func(*args)
  File /usr/local/lib/python2.6/urllib2.py, line 510, in
http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com


On Sun, Jan 11, 2009 at 5:58 AM, alex goretoy
aleksandr.gore...@gmail.comwrote:

 I would try:

 site=http://www.bput.org/;
 payloads=scriptalert('xss')/script
 attack= urllib2.urlopen(site+payloads,80).readlines()


 -Alex Goretoy
 http://www.alexgoretoy.com
 somebodywhoca...@gmail.com



 On Sun, Jan 11, 2009 at 2:49 AM, Steve Holden st...@holdenweb.com wrote:

 Paul Rubin wrote:
  asit lipu...@gmail.com writes:
  site=www.bput.org
  payloads=scriptalert('xss')/script
  attack= urllib2.urlopen(site+payloads,80).readlines()
 
  according to my best knowledge, the above code is correct.
  but why it throws exceptio 
 
  The code is incorrect.  Look at the string ou are sending into
  urlopen.  What on earth are you trying to do?

 He's investigating potential cross-site scripting vulnerabilities.

 regards
  Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC  http://www.holdenweb.com/

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



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


Re: math module for Decimals

2009-01-06 Thread alex goretoy
Yes I ran strace python and imported math

time(NULL)  = 1231244692
futex(0x80575d8, FUTEX_WAKE, 1) = 0
stat64(math, 0xbfabef50)  = -1 ENOENT (No such file or
directory)
open(math.so, O_RDONLY|O_LARGEFILE)   = -1 ENOENT (No such file or
directory)
open(mathmodule.so, O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or
directory)
open(math.py, O_RDONLY|O_LARGEFILE)   = -1 ENOENT (No such file or
directory)
open(math.pyc, O_RDONLY|O_LARGEFILE)  = -1 ENOENT (No such file or
directory)
stat64(/usr/lib/python24.zip/math, 0xbfabef50) = -1 ENOENT (No such file
or directory)
open(/usr/lib/python24.zip/math.so, O_RDONLY|O_LARGEFILE) = -1 ENOENT (No
such file or directory)
open(/usr/lib/python24.zip/mathmodule.so, O_RDONLY|O_LARGEFILE) = -1
ENOENT (No such file or directory)
open(/usr/lib/python24.zip/math.py, O_RDONLY|O_LARGEFILE) = -1 ENOENT (No
such file or directory)
open(/usr/lib/python24.zip/math.pyc, O_RDONLY|O_LARGEFILE) = -1 ENOENT (No
such file or directory)
stat64(/usr/lib/python2.4/math, 0xbfabef50) = -1 ENOENT (No such file or
directory)
open(/usr/lib/python2.4/math.so, O_RDONLY|O_LARGEFILE) = -1 ENOENT (No
such file or directory)
open(/usr/lib/python2.4/mathmodule.so, O_RDONLY|O_LARGEFILE) = -1 ENOENT
(No such file or directory)
open(/usr/lib/python2.4/math.py, O_RDONLY|O_LARGEFILE) = -1 ENOENT (No
such file or directory)
open(/usr/lib/python2.4/math.pyc, O_RDONLY|O_LARGEFILE) = -1 ENOENT (No
such file or directory)
stat64(/usr/lib/python2.4/plat-linux2/math, 0xbfabef50) = -1 ENOENT (No
such file or directory)
open(/usr/lib/python2.4/plat-linux2/math.so, O_RDONLY|O_LARGEFILE) = -1
ENOENT (No such file or directory)
open(/usr/lib/python2.4/plat-linux2/mathmodule.so, O_RDONLY|O_LARGEFILE) =
-1 ENOENT (No such file or directory)
open(/usr/lib/python2.4/plat-linux2/math.py, O_RDONLY|O_LARGEFILE) = -1
ENOENT (No such file or directory)
open(/usr/lib/python2.4/plat-linux2/math.pyc, O_RDONLY|O_LARGEFILE) = -1
ENOENT (No such file or directory)
stat64(/usr/lib/python2.4/lib-tk/math, 0xbfabef50) = -1 ENOENT (No such
file or directory)
open(/usr/lib/python2.4/lib-tk/math.so, O_RDONLY|O_LARGEFILE) = -1 ENOENT
(No such file or directory)
open(/usr/lib/python2.4/lib-tk/mathmodule.so, O_RDONLY|O_LARGEFILE) = -1
ENOENT (No such file or directory)
open(/usr/lib/python2.4/lib-tk/math.py, O_RDONLY|O_LARGEFILE) = -1 ENOENT
(No such file or directory)
open(/usr/lib/python2.4/lib-tk/math.pyc, O_RDONLY|O_LARGEFILE) = -1 ENOENT
(No such file or directory)
stat64(/usr/lib/python2.4/lib-dynload/math, 0xbfabef50) = -1 ENOENT (No
such file or directory)
open(/usr/lib/python2.4/lib-dynload/math.so, O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0755, st_size=12716, ...}) = 0
open(/usr/lib/python2.4/lib-dynload/math.so, O_RDONLY) = 4
read(4, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\16..., 512) =
512
fstat64(4, {st_mode=S_IFREG|0755, st_size=12716, ...}) = 0
mmap2(NULL, 15588, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 4, 0) =
0xb7f2b000
mmap2(0xb7f2e000, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 4, 0x2) = 0xb7f2e000
close(4)= 0
close(3)= 0

It's probably because I only downloaded python from svn repo and ran
./configuremakemake install

I didn't do anything else. Like set PYTHONPATH. I solved it though. You can
tell by the output it's looking for it in my other python install lib path.

Thank you.
-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com


On Tue, Jan 6, 2009 at 10:44 AM, Mark Dickinson dicki...@gmail.com wrote:

 dule built, but Python is looking in the wrong
 place for it, for some reason.

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


Re: python is great

2009-01-06 Thread alex goretoy

 I use Andrea Gavana's GUI2Exe to create my binaries. He recently added
 a py2app wrapper to it. I don't have a Mac, so I haven't tested that
 part of his app. However, the py2exe portion rocks! I put in the path
 to my main Python executable, add any special 3rd party modules and it
 just works! I've written a tutorial for the py2exe part of it if
 you're interested...


Can you post the link to this tutorial?

If you want to save me the trouble, then I'd like to see those notes.
 If you want, I can host the notes at dotancohen.com to that they will
 be publicaly accessible.

Any more news on this research?

-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com


On Tue, Jan 6, 2009 at 9:24 PM, Mike Driscoll kyoso...@gmail.com wrote:

 On Jan 6, 2:24 pm, Joe Strout j...@strout.net wrote:
  M.-A. Lemburg wrote:
   On the Mac in particular, if you want
   your app to run on any PowerPC or Intel machine runing 10.4 or later,
   and you're using anything not in the standard framework (such as
   MySQLdb), it's a bit of a nightmare.
 
   You're looking for py2app:
 
  http://undefined.org/python/py2app.html
 
  No, I'm *using* py2app.  I've been trying to use it for a couple of
  weeks now, with the generous help of such people as Robin Dunn, and I
  still don't have it quite working properly.  (I'd be happy to send you
  my notes on what was required to get as far as I've gotten, but it's
  several pages, a bit long to post here.)
 
  (py2exe works a little more easily, thank goodness.)
 
   So I would say that Python as a language is great, and its standard
   framework is great.  But its (many) IDEs are pretty poor, and the
   process of building a polished, packaged app is abysmal.
 
   It's certainly work, but that's always the case for nicely polished
   apps :-)
 
  In Python, yes.  :)  Not in all environments.
 
   For packaging, you can choose from a multitude of installer builders -
   none of which are really Python specific.
 
  I'm not even talking about that level of packaging -- I'm just talking
  about making something that appears to the user like a normal
  executable, which they can double-click on their system and have it
  actually run, rather than aborting with something unhelpful like No
  module named MySQLdb.
 
   And there are
   some things (such as Flash-style web applets) that you still can't do
 at
   all in Python, even after all these years.
 
   You're looking for Silverlight:
  http://www.voidspace.org.uk/ironpython/silverlight/index.shtml
 
  Maybe.  I'm not a big fan of anything so Microsoftian, but I'll admit
  that this does mostly fit the bill I described above (or has the
  potential to, anyway).
 
  Thanks,
  - Joe

 I use Andrea Gavana's GUI2Exe to create my binaries. He recently added
 a py2app wrapper to it. I don't have a Mac, so I haven't tested that
 part of his app. However, the py2exe portion rocks! I put in the path
 to my main Python executable, add any special 3rd party modules and it
 just works! I've written a tutorial for the py2exe part of it if
 you're interested...

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

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


Re: Python training in Colorado, January 27-30

2009-01-05 Thread alex goretoy
 users, programmers, hackers, etc...

Don't get me wrong, It's nothing personal against Microsoft. I just don't
like how so many people are wasting there time with it. Especially when
there are significantly way better things out there to feed you mind and
your computer. In an unrestrictive so much environment as windows.
Especially for development.

Sorry this is long and off topic. (I need to learn how to write better.)
It's just some things I think about sometimes. Please help me some how to
achieve this goal. I want people to really harness the true power of there
computer and stop eating BS for applications and development environments.
If there is more sand, then there's more sand castles, holes and fun. Why
would someone want to pass up the ability to use the same thing in so many
more ways than one. It doesn't compute. By all means I'm not trying to steal
your thread. Please don't feel that way.

-Alex Goretoy
http://www.alexgoretoy.com



On Mon, Jan 5, 2009 at 6:47 PM, s...@pobox.com wrote:


lutz Per my web page, my classes may be available in a different
lutz location later this year (Florida is a strong possibility), but
lutz not in Tulsa, unfortunately.

 Maybe if Tulsa had more appealing geography or weather??? ;-)

 Skip

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


Re: math module for Decimals

2009-01-05 Thread alex goretoy

 Hmm.  Maybe we shouldn't be using this syntax in from_float, if it's
 the only thing that prevents the trunk version of decimal.py from
 being used with Python 2.4.  On the other hand, from_float isn't
 going to work until 2.7 anyway, since it uses a whole bunch of
 new stuff:  as_integer_ratio and copysign (both introduced in 2.6),
 and bit_length (introduced in 2.7).


I so new to python that I'm not sure that anything I can say may help as
much as someone with more experience. I would leave is compatability to be
decided by what other functions it relies on.(as_integer_ratio and copysign)
Throw the rest out the window.

Since that would make this function more bulky and I don't think there will
be that many people wanting to use it with 2.4, OTOH I'm using BackTrack2
and it comes with python2.4.3

I started building my little program using ubuntu with python2.5.x, then I
started to use my other option for dual-boot. Backtrack2 is an old time
favorite and is alot faster for me to use when running X,firefox(with
anywhere from 15-100 tabs open),konqueror,etc

Ialready installed other versions of python for bt, no problem there. I'm
just wondering about this import error in decimal.py inside python2.7a0(svn
repo), don't let curiosity kill this cat.

I just wanted to let All know what decimal.py is doing on my pc. Maybe I'm
the only one getting this? This version of python2.7 is from python's svn
repo. Is the python repo considered to be unstable(wrong word?) and this is
expected?

I get this when importing decimal:

Python 2.7a0 (trunk:68339M, Jan  5 2009, 05:18:41)
[GCC 3.4.6] on linux2
Type help, copyright, credits or license for more information.
 import decimal
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/local/lib/python2.7/decimal.py, line 138, in module
import math as _math
ImportError: No module named math



Are other people seeing this as well? Just curious.
--
http://mail.python.org/mailman/listinfo/python-list


Re: threading a 10 lines out of a file

2009-01-05 Thread alex goretoy
Steve,

Are you referring to the endless GIL debate? I googled about what you said.
I'll look into it here shortly. I just know one thing, is that I need a
comparison for regular code and something about how GIL and threading fit in
the picture. It makes it easier for me to understand what is going on. Can
you post an example? something I can use to truely thread a for loop? The
example previously posted show that it works 10 times faster than original
for loop. My current program runs for 4.5 hours. I think it will be good to
minimize that by 10 times. But if It can do more/faster, than that would be
great. TIA for all your help.

-Alex Goretoy
http://www.alexgoretoy.com



On Mon, Jan 5, 2009 at 6:13 PM, Steve Holden st...@holdenweb.com wrote:

 re, however, that the CPython implementation won't net you any
 benefit if all threads are CPU-bound, since due to something called the
 GIL (global interpreter lock) no two threads will run concurrently.

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


Re: threading a 10 lines out of a file

2009-01-05 Thread alex goretoy

 Se we need to know a bit more about your 4.5-hour program before we can
 determine whether threads can help. There is light at the end of the
 tunnel, however, since even if threads don't work it's possible that the
 multiprocessing module will (assuming you have multi-processor hardware
 at your disposal).

What my program is doing is sending each line to a function that processes
it via pycurl(with urllib fallback),mysqlDB(with _mysql fallback). It check
the mysql database to see if this line exists. If it doesn't then it sends
it either via mysql query or pycurl. Depending on the option set in the
functions. Some sections of the function  have time.sleep(6) in them.
Otherwise things won't work. This considerably slows down performance. If I
thread all lines then it will process more at the same time. So that means
there will be like 10 or set amount threads running doing all steps in the
functions. posting forms, performing queries and waiting for form postings
to process on the server, etc... I hope this adds more light at the end of
that tunnel. It currently works under my ubuntu install of python(2.5.x) and
bt's python(2.4.3). Then reason why I added a fallback to MySQLdb and pycurl
is then a person can install this on a server that is hosted elsewhere.
Where you can't install python modules, due to permissions and such. I want
it to work everywhere. There's alot more to this application, I'm not sure I
can disclose at the moment. Seeing as it can be used for good or bad. I
don't want it to get in the wrong hands if it's public. OTOH, I think I'll
make it public. That's all up in the air at the moment. One thing it that it
does make life easier for me. A lot easier. Although, I haven't made money
with it. Yet. Plus, I want to make pyGTK frontend for it. Looking into that
too. I wouldn't be against a private team assembling to create this though.
As long as I can get money out of it somehow. Cuz I'm broke. and I live with
my mom. Not sure how anyone can help me there. But I'll throw it up in the
air for all to see. Maybe somethings comes out of it. This program is an
idea I've been building inside my garage(my room) for about a year and a
half. Built in PHP and python, now.

Would something that uses pycurl,mysql be good for threading? It doesn't run
on SMP but maybe one day.

I also need to look into how to make a python package out of it. I
researched some stuff awhile ago, but I didn't quite need it then. I just
wanted to see what I'm getting into.  Any other stuff about this would be
appreciated to. Although of topic. Sorry.

By the way, I wanted to really thank everyone for all your help. It means a
lot to me.

-Alex Goretoy
http://www.alexgoretoy.com



On Mon, Jan 5, 2009 at 9:17 PM, Steve Holden st...@holdenweb.com wrote:

 I did, once upon a time, write code
 that used several hundred threads to send emails, and gave a dramatic
 speed-up (because of the network-bound nature of the task). Can I
 presume that your original inquiry was a toy, and that your real problem
 is also IO-bound? Otherwise I am unsure how you will benefit by
 threading - if your line-processing tasks don't contain any IO then
 using a threaded approach will not yield any speed-up at all.

 The example you quoted achieved its speed-up because a thread releases
 the GIL while waiting for a network response, allowing other threads to
 process. Thus it effectively ran all the pings in parallel.

 Se we need to know a bit more about your 4.5-hour program before we can
 determine whether threads can help. There is light at the end of the
 tunnel, however, since even if threads don't work it's possible that the
 multiprocessing module will (assuming you have multi-processor hardware
 at your disposal).

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


Re: multiprocessing vs thread performance

2009-01-05 Thread alex goretoy
There doesn't seem to be any good examples on POSH or it's not clear to me.
For when using with a for loop like mk is doing who started this thread. How
would somethings like this be possible to do with POSH? The example show how
to share variables between processes/threads but nothing about How the
thread starts or a for loop.

-Alex Goretoy
http://www.alexgoretoy.com
somebodywhoca...@gmail.com


On Sat, Jan 3, 2009 at 1:31 PM, Nick Craig-Wood n...@craig-wood.com wrote:

 mk mrk...@gmail.com wrote:
   After reading http://www.python.org/dev/peps/pep-0371/ I was under
   impression that performance of multiprocessing package is similar to
   that of thread / threading. However, to familiarize myself with both
   packages I wrote my own test of spawning and returning 100,000 empty
   threads or processes (while maintaining at most 100 processes / threads
   active at any one time), respectively.
 
   The results I got are very different from the benchmark quoted in PEP
   371. On twin Xeon machine the threaded version executed in 5.54 secs,
   while multiprocessing version took over 222 secs to complete!
 
   Am I doing smth wrong in code below?

 Yes!

 The problem with your code is that you never start more than one
 process at once in the multiprocessing example.  Just check ps when it
 is running and you will see.

 My conjecture is that this is due to the way fork() works under unix.
 I think that when the parent forks it yields the CPU to the child.
 Because you are giving the child effectively no work to do it returns
 immediately, re-awakening the parent, thus serialising your jobs.

 If you give the children some work to do you'll see a quite different
 result.  I gave each child time.sleep(1) to do and cut down the total
 number to 10,000.

 $ ./test_multiprocessing.py
 == Process 1000 working ==
 == Process 2000 working ==
 == Process 3000 working ==
 == Process 4000 working ==
 == Process 5000 working ==
 == Process 6000 working ==
 == Process 7000 working ==
 == Process 8000 working ==
 == Process 9000 working ==
 == Process 1 working ==
 === Main thread waiting for all processes to finish ===
 Total time: 101.382129192

 $ ./test_threading.py
 == Thread 1000 working ==
 == Thread 2000 working ==
 == Thread 3000 working ==
 == Thread 4000 working ==
 == Thread 5000 working ==
 == Thread 6000 working ==
 == Thread 7000 working ==
 == Thread 8000 working ==
 == Thread 9000 working ==
 == Thread 1 working ==
 Total time:  100.659118176

 So almost identical results and as expected - we ran 10,000 sleep(1)s
 in 100 seconds so we must have been running 100 simultaneously.

 If you replace the time.sleep(1) with for _ in xrange(100):
 pass you get this much more interesting answer on my dual core linux
 laptop, showing nicely the effect of the contention on the python
 global interpreter lock and how multiprocessing avoids it.

 $ ./test_multiprocessing.py
 == Process 1000 working ==
 == Process 2000 working ==
 == Process 3000 working ==
 == Process 4000 working ==
 == Process 5000 working ==
 == Process 6000 working ==
 == Process 7000 working ==
 == Process 8000 working ==
 == Process 9000 working ==
 == Process 1 working ==
 === Main thread waiting for all processes to finish ===
 Total time: 266.808327913

 $ ./test_threading.py
 == Thread 1000 working ==
 == Thread 2000 working ==
 == Thread 3000 working ==
 == Thread 4000 working ==
 == Thread 5000 working ==
 == Thread 6000 working ==
 == Thread 7000 working ==
 == Thread 8000 working ==
 == Thread 9000 working ==
 == Thread 1 working ==
 Total time:  834.81882

 --
 Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
 --
 http://mail.python.org/mailman/listinfo/python-list

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


  1   2   >