Re: List spam

2011-08-20 Thread George
I find python group is filled with spam mails, is there any way to filter
these mails before sending it to the group.
I can't see this situation with similar user group, such as the jsr.

George.


On 20/08/2011 07:07, "Ben Finney"  wrote:

> Javier  writes:

> You will lose a lot of people
> asking/answering interesting stuff, and
> maybe eventually the list will
> die.

I don't think it would die, but the chances are greater that it
> would
become insular and further disconnected from the Python community,
> and
hence far less useful.

> Me (like many people with little free time)
> seldom post in
> blogs/forums/mailing lists where I need to register.

+1

--
> 
 \  ³Ignorance more frequently begets confidence than does |
  `\
> knowledge.² ‹Charles Darwin, _The Descent of Man_, 1871 |
_o__)
> |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list



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


Re:Python thread

2011-09-01 Thread George
Hi,
Why doesn't python threads show an associated PID?  On spawning python
threads using the threading module I can only see the main thread's pid on
using top or ps unix command, no  subprocesses are displayed. In otherwords
top or ps in not aware of any subprocesses created using threading module in
python. 

Whereas in Java , creating threads will result in separate pid , these
subprocesses can be listed using top or ps. Java threads get mapped to the
cores in the system.
  
Does it mean that python threads are not mapped to the core in the system.
On using multiprocessing module, separate processes are created with unique
PID. 


Any input would be great
George


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


Re:PythonThreading

2011-09-01 Thread George
Hi,
Why doesn't python threads show an associated PID?  On spawning python
threads using the threading module I can only see the main thread's pid on
using top or ps unix command, no  subprocesses are displayed. In otherwords
top or ps in not aware of any subprocesses created using threading module in
python.

Whereas in Java , creating threads will result in separate pid , these
subprocesses can be listed using top or ps. Java threads get mapped to the
cores in the system.

Does it mean that python threads are not mapped to the core in the system.
On using multiprocessing module, separate processes are created with unique
PID.


Any input would be great
George


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


Re: Python thread

2011-09-01 Thread George
So what exactly does threading module do, if it doesn't create a subprocess.
Does each thread have its own stack and PC.
What advantage would a threading module provide over sequential execution.


On 01/09/2011 22:54, "Terry Reedy"  wrote:

> On 9/1/2011 5:14 PM, George wrote:
>> Hi,
>> Why doesn't python threads show an associated PID?  On spawning python
>> threads using the threading module I can only see the main thread's pid on
>> using top or ps unix command, no  subprocesses are displayed. In otherwords
>> top or ps in not aware of any subprocesses created using threading module in
>> python.
> 
> Perhaps because threads are not subprocesses?
> 
>> Whereas in Java , creating threads will result in separate pid , these
>> subprocesses can be listed using top or ps. Java threads get mapped to the
>> cores in the system.
>> 
>> Does it mean that python threads are not mapped to the core in the system.
> 
> They all run on the same core.
> 
>> On using multiprocessing module, separate processes are created with unique
>> PID.
> 
> That is why multiprocessing was added.
> 


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


Parsing an HTML a tag

2005-09-24 Thread George
How can I parse an HTML file and collect only that the A tags. I have a
start for the code but an unable to figure out how to finish the code.
HTML_parse gets the data from the URL document. Thanks for the help

def HTML_parse(data):
 from HTMLParser import HTMLParser
 parser = MyHTMLParser()

 parser.feed(data)

 class MyHTMLParser(HTMLParser):

  def handle_starttag(self, tag, attrs):

  def handle_endtag(self, tag):

def read_page(URL):
 "this function returns the entire content of the specified URL
document"
 import urllib
 connect = urllib.urlopen(url)
 data = connect.read()
 connect.close()
 return data

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


Re: Parsing an HTML a tag

2005-09-24 Thread George
I'm very new to python and I have tried to read the tutorials but I am
unable to understand exactly how I must do this problem.

Specifically, the showIPnums function takes a URL as input, calls the
read_page(url) function to obtain the entire page for that URL, and
then lists, in sorted order, the IP addresses implied in the "" tags within that page.


"""
Module to print IP addresses of tags in web file containing HTML

>>> showIPnums('http://22c118.cs.uiowa.edu/uploads/easy.html')
['0.0.0.0', '128.255.44.134', '128.255.45.54']

>>> showIPnums('http://22c118.cs.uiowa.edu/uploads/pytorg.html')
['0.0.0.0', '128.255.135.49', '128.255.244.57', '128.255.30.11',
'128.255.34.132', '128.255.44.51', '128.255.45.53',
'128.255.45.54', '129.255.241.42', '64.202.167.129']

"""

def read_page(url):
 import formatter
 import htmllib
 import urllib

 htmlp = htmllib.HTMLParser(formatter.NullFormatter())
 htmlp.feed(urllib.urlopen(url).read())
 htmlp.close()

def showIPnums(URL):
 page=read_page(URL)

if __name__ == '__main__':
 import doctest, sys
 doctest.testmod(sys.modules[__name__])

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


Struggling with this concept please help

2005-09-25 Thread George
Hello everyone I know many have helped but I cannot get this to work
out correctly. I cannot use BeautifulSoup at all. I need to:
  Parse the HTML and extracting all the links, convert them to IP
addresses, and build a list of all these IP addresses, thwn I need to
sort the list and remove the duplicates so that unit testing will work.
Please help I have never done python before and I can't seem to get the
hang of it.

"""
Module to print IP addresses of tags in web file containing HTML

>>> showIPnums('http://22c118.cs.uiowa.edu/uploads/easy.html')
['0.0.0.0', '128.255.44.134', '128.255.45.54']


>>> showIPnums('http://22c118.cs.uiowa.edu/uploads/pytorg.html')
['0.0.0.0', '128.255.135.49', '128.255.244.57', '128.255.30.11',
'128.255.34.132', '128.255.44.51', '128.255.45.53',
'128.255.45.54', '129.255.241.42', '64.202.167.129']

"""

import htmllib
import formatter
import urllib
import socket

from urlparse import urlparse

class HTML_Parser(htmllib.HTMLParser):
def __init__(self):
htmllib.HTMLParser.__init__(self,
formatter.AbstractFormatter(formatter.NullWriter()))


def start_a(self, args):
for key, value in args:
if key.lower() == 'href':
global listURL

def showIPnums(URL):
 parser = HTML_Parser()
 connect = urllib.urlopen(URL)
 data =  connect.read()
 parser.feed(data)
 parser.close()
 connect.close()

if __name__ == '__main__':
 import doctest, sys 
 doctest.testmod(sys.modules[__name__])

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


Re: Struggling with this concept please help

2005-09-25 Thread George
Not allowed to use Beautiful Soup because of the very important built
ins that is provides that makes it very simple to complete this
problem. Not my choice . This is a review question for our final in two
months and I just want to get things going so I can try to understand
things better. Please help.

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


form filling XML

2005-10-13 Thread George
How can I do the following in python:

given two strings:
form="""

  My Sample Web Page  


What are the weekdays?

Monday
Tuesday
Wednesday
Thursday
Friday




"""
fillin="""

maandag
dinsdag
woensdag
donderdag
vrijdag
zaterdag
zondag

"""

How can I compare the text in the element tags  with the elements
tags in filling and if they match replace the text within the elements
tags  with the text in the matching element tag of fillin.
For example Since the text Monday in form matches the Element tag
 in fillin put maandag in the element tag  of Monday.

Kind of a Pseudo Code

import xml.dom.minidom

def xmlform(form=None, fillin=None):
 Fo = xml.dom.minidom.parseString(form)
 Fi = xml.dom.minidom.parseString(fillin)

 Fo information:
 get element tags for li
 get text for li

 Fi information:
 get childtags for dutchdays

 if(text for li=child tags for dutchdays):
   replace child tags for dutchdays text with text for li

There needs to be a loop but I cannot figure out what type of loop
maybe a while len(Fo)>0: to process through the form.

Thanks for the help!!

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


XML dom question

2005-10-14 Thread George
How can I do the following in python:

compare the text in the element tags  with the elements
tags in filling and if they match replace the text within the elements
tags  with the text in the matching element tag of fillin.
For example Since the text Monday in form matches the Element tag
 in fillin put maandag in the element tag  of Monday.


Kind of a Pseudo Code

 Fo information:
 get element tags for li
 get text for li


 Fi information:
 get childtags for dutchdays


 if(text for li=child tags for dutchdays):
   replace child tags for dutchdays text with text for li

Some pieces of code that I tried out but cannot put together to get the
results.

import xml.dom.minidom
from xml.dom.minidom import parseString
import xml.xpath

form="""

  My Sample Web Page  


What are the weekdays?

Monday
Tuesday
Wednesday
Thursday
Friday




"""
fillin="""

maandag
dinsdag
woensdag
donderdag
vrijdag
zaterdag
zondag

"""


fo=xml.dom.minidom.parseString(form)
fi=xml.dom.minidom.parseString(fillin)

mon=fi.getElementsByTagName('Monday')
monlist=mon[0]
m=monlist.childNodes[0]
mo=m.data
fri=fi.getElementsByTagName('Friday')
frilist=fri[0]
f=frilist.childNodes[0]
fr=f.data

for li in xml.xpath.Evaluate("//li", form_doc):
 li.normalize()
 day_text = li.childNodes[0]
 day_str = day_text.nodeValue


Thanks for the help!!

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


Re: XML dom question

2005-10-15 Thread George
Yes but I cannot get the if statement to work to compare the two or the
replaceChild portion to work. Could someone help me with that.

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


Please Help with replaceChild

2005-10-16 Thread George
How can I do the following in python:


compare the text in the element tags  with the elements
tags in filling and if they match replace the text within the elements
tags  with the text in the matching element tag of fillin.
For example Since the text Monday in form matches the Element tag
 in fillin put maandag in the element tag  of Monday.


Kind of a Pseudo Code


 Fo information:
 get element tags for li
 get text for li


 Fi information:
 get childtags for dutchdays


 if(text for li=child tags for dutchdays):
   replace child tags for dutchdays text with text for li


Some pieces of code that I tried out but cannot put together to get the
results.

import xml.dom.minidom
from xml.dom.minidom import parseString
import xml.xpath

form="""

  My Sample Web Page  


What are the weekdays?

Monday




"""

fillin="""

maandag
dinsdag
woensdag
donderdag
vrijdag
zaterdag
zondag

"""

Fo = xml.dom.minidom.parseString(form)
Fi = xml.dom.minidom.parseString(fillin)

form_doc = parseString(form)
fill_doc = parseString(fillin)

for li in xml.xpath.Evaluate("//li", form_doc):
 li.normalize()
 day_text = li.childNodes[0]
 day_str = day_text.nodeValue
 for Monday in xml.xpath.Evaluate("//Monday", fill_doc):
  Monday.normalize()
  mon_text = Monday.childNodes[0]
  mon_str = mon_text.nodeValue
  #I want the to put the replace here put I have tried everything and
errors keep coming up

I am totally lost and do not know what to do could someone explain to
me what to do because I have looked at the python.org material and have
accomplished nothing.

Thanks

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


Automate decryption using GnuPGInterface

2005-11-30 Thread George
Hi,
   Does anyone have any experience with GnuPGInterface? I'm having a
problem with decrypting files through a cron job. The below job works
great when I run it manually from the command line, but it blows up
whenever I try to run it through cron, and I can't really figure out
why. I've been trying to learn python, and I'm at the point where I can
get things working in small scripts (you know, just enough to be
dangerous). If anybody could shed some light as to what I might be
doing wrong, I would really appreciate it. TIA...

#!/usr/local/bin/python

import os, glob, time, GnuPGInterface

gnupg = GnuPGInterface.GnuPG()
gnupg.options.extra_args.append('--no-secmem-warning')
gnupg.passphrase = ##

# get list of files in /home/ns1
# that match regex pattern
for pgpname in glob.glob("/home/ns1/[ABDP]*.pgp"):
txtname = pgpname.replace('.pgp','.txt')
inputfile = file(pgpname,'r')
outputfile = file(txtname,'w')

process = gnupg.run(['--decrypt'],
attach_fhs={'stdin':inputfile,'stdout':outputfile})

process.wait()  # cleanup
inputfile.close()
outputfile.close()

os.remove(pgpname)

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


Re: Automate decryption using GnuPGInterface

2005-11-30 Thread George
I have 5 python scripts I've added to cron over the past year that run
correctly all the time. I double-checked the permissions and paths and
everything looks good there. Here's the cron entry that I just tested
with:
23   12   *   *   *   /usr/local/bin/decrypt_test.py >
/usr/local/bin/decrypt.log 2>&1

As for "blowing up", I get the typical stack trace, but I'm not
python-savvy enough to quite figure it out:

Traceback (most recent call last):
  File "/SHCD/scripts/decrypt_certegy.py", line 18, in ?
attach_fhs={'stdin':inputfile,'stdout':outputfile})
  File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
357, in run
create_fhs, attach_fhs)
  File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
401, in _attach_fork_exec
if process.pid == 0: self._as_child(process, gnupg_commands, args)
  File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
442, in _as_child
os.execvp( command[0], command )
  File "/usr/local/lib/python2.2/os.py", line 298, in execvp
_execvpe(file, args)
  File "/usr/local/lib/python2.2/os.py", line 352, in _execvpe
raise exc, arg
OSError: [Errno 2] No such file or directory
/home/ns1/PTAccountTransfer.051130022347.pgp
Traceback (most recent call last):
  File "/SHCD/scripts/decrypt_certegy.py", line 20, in ?
process.wait()  # cleanup
  File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
639, in wait
raise IOError, "GnuPG exited non-zero, with code %d" % (e << 8)
IOError: GnuPG exited non-zero, with code 65536


I'm guessing it has something to do with stdin, stdout, and cron, but I
can't figure out any more than that, or how I would go about changing
it.

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


Re: MySQLdb

2005-01-28 Thread George
Daniel Bowett wrote:

> Daniel Bowett wrote:
>> I have just started playing around with MySQLdb for a project I am
>> planning.
>> 
>> As a test I have written a script that executes 3000 insert statements
>> on a table. The table contains 10 fields with a mix of text and numbers
>> - its a product table for a website eg UPC, ProductName, Price etc.
>> 
>> The problem I have is that it takes just over two minuted to execute the
>> 3000 insert statements which seems really slow! I am running it on a
>> machine with a 1.5 Ghz Pentium M Processor and Gig Of Ram. I dont think
>> the machine is to blame for the speed because during execution the
>> processor sits at about 10% and there is loads of free RAM.
>> 
>> Does anyone know if this sort of speed sounds right?
>> 
>> Cheers,
>> 
>> Dan.
>> 
>> 
> 
> UPDATE
> --
> 
> I have found the "executemany" function! It now takes around a second to
> complete the 3000 inserts.
> 
> Lesson learnt - I should have posted my code...
> 
> Thanks for your help everyone.

Hi Daniel,

I was just wondering the executemany sends the insert as batch, does it?
That is what I was going to suggest for speed MySQL should process this
very quickly as a batch the problem was probably getting them there.

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


Reading registry export files

2005-06-22 Thread George
Hi,

I have exported some registry-keys using Regedit to a number of 
.reg-files. I can open these files using any text editor. Now I wanted 
to write a simple Python script to concatenate all these files to one 
output file. (Please note that I'm a newbie).

However, if I do something like:

 >>> f=open('c:/documents and settings/myname/desktop/test.reg','r')
 >>> r=f.read()
 >>> print r

I get a lot of garbage with a lot characters which the Python shell 
cannot display (it display a square instead). The above code does work 
with ordinary text files.

Should I open these reg-files in a different way, or treat them 
differently once read in Python?

Thanks for any help.

Kind regards, George
-- 
http://mail.python.org/mailman/listinfo/python-list


Expected Value

2005-09-09 Thread George
I have never done any programming with python in my life so I will most
definetly need help understanding how I can accomplish this part of my
program.

The function expectP(z) computes E(X) for the random variable
representing a sample over the probability generated by "pf" for the
set of discrete items [1,10]. The constant c is needed so that the
probability sum to 1.0, as required by the definition of probability.
The function pf(r,c,x) returns the probability that item x will be
equal to a randomly chosen variable, denoted by P(x) or P(X=x) in
mathematical texts, where c is the constant mentioned above and r is
needed because we are considering a power law distribution. I need help
in writing the expectP function and do I compile and execute this code
on a linux box.

"""
Module to compute expected value.

>>> showExpectP(0.5)
33410
>>> showExpectP(0.85)
15578
>>> showExpectP(0.9)
12953
>>> showExpectP(0.99)
8693
>>> showExpectP(0.999)
8312

"""

def norm(r):
  "calculate normalization factor for a given exponent"
  # the function for this distribution is  P(x) = c*(x**-r)
  # and the job of this norm function is to calculate c based
  # on the range [1,10**5]
  sum = 0.0
  for i in range(1,1+10**5):
 # final sum would be more accurate by summing from small values
 # to large ones, but this is just a homework, so sum 1,2,..10**5
 sum += float(i)**-r
  return 1.0/sum

def pf(r,c,x):
  "return a power-law probability for a given value"
  # the function for this distribution is  P(x) = c*(x**-r)
  # where the constant c is such that it normalizes the distribution
  return c*(float(x)**-r)

#- between these lines, define expectP() function
-


#- end of expectP() definition


def showExpectP(limit):
  "display ExpectP(limit) by rounding down to nearest integer"
  k = expectP(limit)
  return int(k)

if __name__ == '__main__':
  import doctest, sys
  doctest.testmod(sys.modules[__name__]) 

thankyou sooo much.

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


Expected Value

2005-09-10 Thread George
How would I get the expected value out of this information. I have
tried many times to understand this but am unable to.

  The function expectP(z) computes E(X) for the random variable
representing a sample over the probability generated by "pf" for the
set of discrete items [1,10]. The constant c is needed so that the
probability sum to 1.0, as required by the definition of probability.
The function pf(r,c,x) returns the probability that item x will be
equal to a randomly chosen variable, denoted by P(x) or P(X=x) in
mathematical texts, where c is the constant mentioned above and r is
needed because we are considering a power law distribution.

The function expectP(z) computes E(X) with r=z, using pf(r,c,x) where x
ranges over the set of discrete items in [1,10]

The program:

def norm(r):
  "calculate normalization factor for a given exponent"
  # the function for this distribution is  P(x) = c*(x**-r)
  # and the job of this norm function is to calculate c based
  # on the range [1,10**5]
  sum = 0.0
  for i in range(1,1+10**5):
 # final sum would be more accurate by summing from small values
 # to large ones, but this is just a homework, so sum 1,2,..10**5
 sum += float(i)**-r
  return 1.0/sum

def pf(r,c,x):
  "return a power-law probability for a given value"
  # the function for this distribution is  P(x) = c*(x**-r)
  # where the constant c is such that it normalizes the distribution
  return c*(float(x)**-r)

#- between these lines, define expectP() function
-


#- end of expectP() definition


def showExpectP(limit):
  "display ExpectP(limit) by rounding down to nearest integer"
  k = expectP(limit)
  return int(k)

if __name__ == '__main__':
  import doctest, sys 
  doctest.testmod(sys.modules[__name__])

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


Launch file in Notepad

2005-05-12 Thread George
Newbie question:

I'm trying to lauch Notepad from Python to open a textfile:

import os
b1="c:\test.txt"
os.system('notepad.exe ' + b1)

However, the t of test is escaped by the \, resulting in Notepad trying 
to open "c: est.txt".

How do I solve this?

(By the way, b1 comes from a command line parameter, so the user enters 
c:\test.txt as command line parameter.)

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


Re: Launch file in Notepad

2005-05-12 Thread George
Richie Hindle wrote:
>>By the way, b1 comes from a command line parameter, so the user enters 
>>c:\test.txt as command line parameter.
> 
> 
> How are you prompting the user?  When I run this:
> 
> import os
> b1=raw_input("Enter a filename: ")
> os.system('notepad.exe ' + b1)
> 
> and enter c:\test.txt, it works as expected.

So it does with me, but the user does not enter the filename, he 
launches my Python script file from the DOS-prompt with a command line 
parameter, for example:

test.py c:\test.txt

In that case the \ escapes the t. (read on!)

That is, until now. For some very strange reason it suddenly works as 
expected. I don't understand it anymore, but never mind. Maybe I changed 
my little proggie somehow, causing it accidentally to work. Thanks anyway.

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


Re: Launch file in Notepad

2005-05-12 Thread George
Grant Edwards wrote:
 > On 2005-05-12, Brian van den Broek <[EMAIL PROTECTED]> wrote:

 > Does Python really look at the string and mess with the slash?
 > I don't think it needs to, since the Windows system calls have
 > always accepted forward slashses, haven't they?

It did, but now not anymore. I don't understand why, maybe I've changed 
something in the code. See my other post.

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


Re: Launch file in Notepad

2005-05-12 Thread George
Bengt Richter wrote:
> On Thu, 12 May 2005 15:41:14 +0200, George <[EMAIL PROTECTED]> wrote:

>>(By the way, b1 comes from a command line parameter, so the user enters 
>>c:\test.txt as command line parameter.)
> 
> It should be ok then, unless you have somehow processed the command line 
> parameter and interpreted
> the backslash as an escape. E.g., pargs.py here prints command line args and 
> backslash is
> an ordinary string character as you see in argv[3] below. If it were a tab, 
> you would see
> whitespace instead of the backslash.

Perhaps that's what I did (processing the command line parameter). For 
some reason it works now.

> If by "command line" you mean your own programmed input, make sure you use 
> raw_input, not input, e.g.,

I was referring to the user launching my script with a filename as 
parameter:

test.py c:\test.txt

Here's my code so far (it removes blank lines from the input file (for 
example c:\test.txt), and creates a new file (c:\test_new.txt) to store 
the output):

import string
import sys
import os
if len(sys.argv)<=1:
 print 'Usage: dbl.py [filename]'
 sys.exit()
b1=sys.argv[1]
b2=b1[:-4] + '_new' + b1[-4:]
f1=open(b1,'r')
f2=open(b2,'w')
r1=f1.readlines()
for r in r1:
 if string.capwords(r)<>'':
 f2.write(r)
f1.close()
f2.close()
print 'Output file: ' + b2
os.system ('start notepad.exe ' + b2)

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


Re: Latest models of Gibson guitars

2007-08-19 Thread George
[EMAIL PROTECTED] wrote:
> On 19 kol, 19:34, [EMAIL PROTECTED] wrote:
>> Reviews of latest models of best guitars, fender, gibson, yamaha, and
>> many more, with pictures and prices.
>>
>> http://spam-guitars.blogspot.com/
>>
>> And if you want to win a free guitar go here
>>
>> http://spamguitars.blogspot.com/
> 
> Hello,
> 
> This is  a newsgroup of programming language Python, stop with this!
> 
> Regards,
> Vedran
> 

Thank Google for it. They own blogspot and officially encourage their 
users to look for click revenue. Then the users spam newsgroups using 
Google, the spammers friend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: moyea flv to video converter keygen

2008-06-19 Thread George
got error on your page--
http://mail.python.org/mailman/listinfo/python-list

Re: Why is python source code not available on github?

2012-06-23 Thread George Silva
http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2

On Sat, Jun 23, 2012 at 9:16 PM, gmspro  wrote:

> Why is python source code not available on github?
>
> Make it available on github so that we can git clone and work on source
> code.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Geodetic functions library GeoDLL 32 Bit and 64 Bit

2012-08-28 Thread George Silva
Hi Fred.

Do you know about proj4? proj4 is opensource library that does the
coordinate transformations side of geospatial for many many already tested
projects.

Does your libraries do anything that proj4 does not?

On Wed, Aug 29, 2012 at 2:51 AM, Fred  wrote:

> Hi developers,
>
> who develops programs with geodetic functionality like world-wide
> coordinate transformations or distance calculations, can use geodetic
> functions of my GeoDLL. The Dynamic Link Library can easily be used with
> most of the modern programming languages like C, C++, C#, Basic, Delphi,
> Pascal, Java, Fortran, Visual-Objects and others to add geodetic
> functionality to own applications. For many programming languages
> appropriate Interfaces are available.
>
> GeoDLL supports 2D and 3D coordinate transformation, geodetic datum shift
> and reference system convertion with Helmert, Molodenski and NTv2 (e.g.
> BeTA2007, AT_GIS_GRID, CHENYX06), meridian strip changing, user defined
> coordinate and reference systems, distance calculation, Digital Elevation
> Model, INSPIRE support, Direct / Inverse Solutions and a lot of other
> geodetic functions.
>
> The DLL is very fast, save and compact because of forceful development in
> C++ with Microsoft Visual Studio 2010. The geodetic functions of the
> current version 12.35 are available in 32bit and 64bit architecture. All
> functions are prepared for multithreading and server operating.
>
> You find a free downloadable test version on
> http://www.killetsoft.de/p_gdlb_e.htm
> Notes about the NTv2 support can be found here:
> http://www.killetsoft.de/p_gdln_e.htm
> Report on the quality of the coordinate transformations:
> http://www.killetsoft.de/t_1005_e.htm
>
> Fred
> Email: info_at_killetsoft.de
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A sad day for the scientific Python community. John Hunter, creator of matplotlib: 1968-2012.

2012-08-29 Thread George Silva
 career a few years ago for a job in industry, he remained
> engaged enough that as of today, he is still the top committer to
> matplotlib; this is the git shortlog of those with more than 1000
> commits to the project:
>
>   2145  John Hunter 
>   2130  Michael Droettboom 
>   1060  Eric Firing 
>
> All of this was done by a man who had three children to raise and who
> still always found the time to help those on the mailing lists, solve
> difficult technical problems in matplotlib, teach courses and seminars
> about scientific Python, and more recently help create the NumFOCUS
> foundation project.  Despite the challenges that raising three
> children in an expensive city like Chicago presented, he never once
> wavered from his commitment to open source.  But unfortunately now he
> is not here anymore to continue providing for their well-being, and I
> hope that all those who have so far benefited from his generosity,
> will thank this wonderful man who always gave far more than he
> received.  Thanks to the rapid action of Travis Oliphant, the NumFOCUS
> foundation is now acting as an escrow agent to accept donations that
> will go into a fund to support the education and care of his wonderful
> girls Rahel, Ava and Clara.
>
> If you have benefited from John's many contributions, please say
> thanks in the way that would matter most to him, by helping Miriam
> continue the task of caring for and educating Rahel, Ava and Clara.
> You will find all the information necessary to make a donation here:
>
> http://numfocus.org/johnhunter
>
> Remember that even a small donation helps! If all those who ever use
> matplotlib give just a little bit, in the long run I am sure that we
> can make a difference.
>
> If you are a company that benefits in a serious way from matplotlib,
> remember that John was a staunch advocate of keeping all scientific
> Python projects under the BSD license so that commercial users could
> benefit from them without worry.  Please say thanks to John in a way
> commensurate with your resources (and check how much a yearly matlab
> license would cost you in case you have any doubts about the value you
> are getting...).
>
> John's family is planning a private burial in Tennessee, but (most
> likely in September) there will also be a memorial service in Chicago
> that friends and members of the community can attend.  We don't have
> the final scheduling details at this point, but I will post them once
> we know.
>
> I would like to again express my gratitude to Travis Oliphant for
> moving quickly with the setup of the donation support, and to Eric
> Jones (the founder of Enthought and another one of the central figures
> in our community)  who immediately upon learning of John's plight
> contributed resources to support the family with everyday logistics
> while John was facing treatment as well as my travel to Chicago to
> assist.  This kind of immediate urge to come to the help of others
> that Eric and Travis displayed is a hallmark of our community.
>
> Before closing, I want to take a moment to publicly thank the
> incredible staff of the University of Chicago medical center.  The
> last two weeks were an intense and brutal ordeal for John and his
> loved ones, but the hospital staff offered a sometimes hard to
> believe, unending supply of generosity, care and humanity in addition
> to their technical competence.  The latter is something we expect from
> a first-rate hospital at a top university, where the attending
> physicians can be world-renowned specialists in their field.  But the
> former is often forgotten in a world often ruled by a combination of
> science and concerns about regulations and liability. Instead, we
> found generous and tireless staff who did everything in their power to
> ease the pain, always putting our well being ahead of any mindless
> adherence to protocol, patiently tending to every need we had and
> working far beyond their stated responsibilities to support us.  To
> name only one person (and many others are equally deserving), I want
> to thank Dr. Carla Moreira, chief surgical resident, who spent the
> last few hours of John's life with us despite having just completed a
> solid night shift of surgical work.  Instead of resting she came to
> the ICU and worked to ensure that those last hours were as comfortable
> as possible for John; her generous actions helped us through a very
> difficult moment.
>
> It is now time to close this already too long message...
>
> John, thanks for everything you gave all of us, and for the privilege
> of knowing you.
>
> Fernando.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Python/ArcPy

2012-12-12 Thread George Silva
even better gis.stackexchange.com


On Wed, Dec 12, 2012 at 9:42 PM, Xavier Ho  wrote:

> You can always try http://stackoverflow.com/search?q=ArcPY, or post your
> question there.
>
> Cheers,
> Xav
>
>
>
> On 13 December 2012 08:07, Michelle Couden wrote:
>
>>  Does anyone know of a website or forum  where there is help for ArcPY
>> (Python) programmers? ESRI’s (GIS) resource center Forums are very busy and
>> my questions go days without an answer. Any suggestions would be great.
>> Thanks!!
>>
>> ** **
>>
>> ** **
>>
>> ** **
>>
>> *Michelle Couden*
>>
>> TPP-T GIS Cartographer
>>
>> Certified GIS Analyst
>>
>> (512) 486-5136
>>
>> Fax (512)486-5153
>>
>> michelle.cou...@txdot.gov
>>
>> ** **
>>
>> Mind the road, not your business.
>>
>> [image: Logo]****
>>
>> ** **
>>
>> ** **
>>
>> ** **
>>
>> ** **
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net
<>-- 
http://mail.python.org/mailman/listinfo/python-list


Algorithm. Tony Gaddis book 2 Starting python3

2013-01-27 Thread george . 15
Hi
Question 3 Chp2 Page 76
Adds2 to a and assigns the result to b.
I have several attemtps,would like to check my answer.help please
At 80 i need all the help i can find.
Thanks George Smart
-- 
http://mail.python.org/mailman/listinfo/python-list


Questionnaire on motivation analysis of open source and open content

2012-02-22 Thread George Tsinarakis

Dear Sirs,

We are researchers in Technical University of Crete and our current 
research is in the field of motivation analysis of open source and open 
content software projects participants. We would like to ask you to fill 
a questionnaire and forward it to people involved in such teams and 
projects. The web address is the following:


https://docs.google.com/spreadsheet/viewform?formkey=dHdqZUgyay0waXNRbWFvV3hleVBZSWc6MQ

All personal information will be kept confidential and will be used for 
academic purposes only. For further information please do not hesitate 
to contact with us.




Thank you in advance

Dr G. Tsinarakis

--
---
Dr.George Tsinarakis
Production and Management Engineer,
CAM Laboratory
Department of Production Engineering and Management
Technical University of Crete
University Campus, 73 100 Chania,
Crete , Greece
Tel: +30 2821 037306
Fax: +30 2821 037551
E -mail: tsinar@ dpem.tuc.gr
---

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


trying to use spec file

2012-04-24 Thread George Georgalis
Hi

I posted this yesterday to compiler-sig, but I'm not sure there is any
traffic there?

There is a rather complex spec file for making rpm of python
interpreter, but I'm only seeing doc on making rpm packages (ie
programs); and, the spec file has difficult errors.

Is anyone interested in the spec file issues, or maybe I should just
make a simple one from it?

-George

-- Forwarded message ------
From: George Georgalis 
Date: Mon, Apr 23, 2012 at 6:18 PM
Subject: trying to use spec file
To: compiler-...@python.org


Hi - hope this list is still active.

I'd like to make an rpm of 2.7.3 with some path and release tweeks.
However the spec file from the main distribution doesn't work for me
and it has some numbers from the prior release at the top (2.6).

-rw-r--r-- 1 1000 1002 13549 Apr  9 16:07
./Python-2.7.3/Misc/RPM/python-2.7.spec

Is it maintained? I would love some help and I can provide further
details (strip stops with files not found); but first I'd like to
confirm this file is working out of the box, for anyone?

I'm invoking it with "rpmbuild -bb python-2.7.spec" and I have all the
stated dependancies installed. Is this a supported path, it might be
easier for me to just create a new spec file?

-George

--
George Georgalis, (415) 894-2710, http://www.galis.org/


-- 
George Georgalis, (415) 894-2710, http://www.galis.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re:Threads in Python

2011-09-01 Thread George Kovoor
Hi,
Why doesn't python threads show an associated PID?  On spawning python
threads using the threading module I can only see the main thread's pid on
using top or ps unix command, no  subprocesses are displayed. In otherwords
top or ps in not aware of any subprocesses created using threading module in
python.

Whereas in Java , creating threads will result in separate pid , these
subprocesses can be listed using top or ps. Java threads get mapped to the
cores in the system.

Does it mean that python threads are not mapped to the core in the system.
On using multiprocessing module, separate processes are created with unique
PID.


Any input would be great
George
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Text Strip() now working constantly.

2018-01-27 Thread George Shen
Hi Python Group,

I am not sure if I am doing this correctly however, I believe I found a bug
that involves the striping of a text string.

I have attached a JPG that clearly illustrate the issue.

I am currently using 2.7.13

In short:
Given a string.
'cm_text.data'
if you try and strip '.data'
the return string will be
'cm_tex'
which drops the last 't'
however, given other text.
'om_ol.data'
the same strip '.data' will return
'om_ol' which is correct!

As for a work around right now I am doing the following.
string_abc = 'some_text.data'
string_next = string_abc.strip('data')
string_final = string_next.strip('.')

Please see the JPG.

Sorry if this has been filed before, if I have filed this incorrectly could
you please provide me a better avenue for future reference.

Regards,
-George J Shen
-- 
https://mail.python.org/mailman/listinfo/python-list


Testing an app protected by Okta authorization code with PKCE flow

2022-04-29 Thread George Fischhof
Hi Folks,

has anyone of you a working solution for testing an app protected by Okta
authorization code with PKCE flow?
Meaning to get a bearer token?

I saw / read several articles about it on the net, and several hacks (that
is not problem now ;) ), but it seems that neither of them works with Okta.

We are using Okta's .net backend stuff and Angular widget

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Popular Python Package 'ctx' Hijacked to Steal AWS Keys

2022-05-25 Thread George Fischhof
Turritopsis Dohrnii Teo En Ming  ezt írta (időpont:
2022. máj. 25., Sze, 15:49):

> Subject: Popular Python Package 'ctx' Hijacked to Steal AWS Keys
>
> Good day from Singapore,
>
> Sharing this article for more awareness.
>
> Article: Popular PyPI Package 'ctx' and PHP Library 'phpass' Hijacked
> to Steal AWS Keys
> Link:
> https://thehackernews.com/2022/05/pypi-package-ctx-and-php-library-phpass.html
>
> Thank you.
>
> Regards,
>
> Mr. Turritopsis Dohrnii Teo En Ming
> Targeted Individual in Singapore
> 25 May 2022 Wed
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi All,

it's got to my mind that PYPA, community, and developers should develop
some mechanism to protect against similar threats.

For example security checkers could be added to the upload flow, before a
package appears, and becomes downloadable.
Compiled parts should be allowed only in source, and security checkers
would check those too, and compile from source and publish package only
after these checks executed and did not found any harmful thing.


BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


exec() an locals() puzzle

2022-07-20 Thread george trojan
I wish I could understand the following behaviour:

1. This works as I expect it to work:

def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
exec('y *= 2')
print('ok:', eval('y'))
f()

{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1, 'y': 1}
ok: 2

2. I can access the value of y with eval() too:

def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
u = eval('y')
print(u)
f()

{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1, 'y': 1}
1

3. When I change variable name u -> y, somehow locals() in the body of
the function loses an entry:

def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
y = eval('y')
print(y)
f()

{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1}

---NameError
Traceback (most recent call last)
Input In [1], in ()  7 print(y)  8 # y
= eval('y')  9 #print('ok:', eval('y'))---> 10 f()

Input In [1], in f()  4 exec('y = i; print(y); print(locals())')
   5 print(locals())> 6 y = eval('y')  7 print(y)

File :1, in 
NameError: name 'y' is not defined1.

Another thing: within the first exec(), the print order seems
reversed. What is going on?

BTW, I am using python 3.8.13.

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


Re: exec() an locals() puzzle

2022-07-21 Thread george trojan
Thanks. That cdef-locals concept is consistent with the following example:

def f():
i = 1
def g(): print('i' in globals(), 'i' in locals())
def h(): print('i' in globals(), 'i' in locals()); i
g()
h()
f()

False False
False True

It is a mystery, which may be why the documentation for globals() and
locals() is 2-line long.


Le mer. 20 juill. 2022, à 19 h 31, Martin Di Paola <
martinp.dipa...@gmail.com> a écrit :

> I did a few tests
>
> # test 1
> def f():
>  i = 1
>  print(locals())
>  exec('y = i; print(y); print(locals())')
>  print(locals())
>  a = eval('y')
>  print(locals())
>  u = a
>  print(u)
> f()
>
> {'i': 1}
> 1
> {'i': 1, 'y': 1}
> {'i': 1, 'y': 1}
> {'i': 1, 'y': 1, 'a': 1}
> 1
>
> # test 2
> def f():
>  i = 1
>  print(locals())
>  exec('y = i; print(y); print(locals())')
>  print(locals())
>  a = eval('y')
>  print(locals())
>  y = a
>  print(y)
> f()
> {'i': 1}
> 1
> {'i': 1, 'y': 1}
> {'i': 1}
> Traceback (most recent call last):
> NameError: name 'y' is not defined
>
>
> So test 1 and 2 are the same except that the variable 'y' is not
> present/present in the f's code.
>
> When it is not present, exec() modifies the f's locals and adds an 'y'
> to it but when the variable 'y' is present in the code (even if not
> present in the locals()), exec() does not add any 'y' (and the next
> eval() then fails)
>
> The interesting part is that if the 'y' variable is in the f's code
> *and* it is defined in the f's locals, no error occur but once again the
> exec() does not modify f's locals:
>
> # test 3
> def f():
>  i = 1
>  y = 42
>  print(locals())
>  exec('y = i; print(y); print(locals())')
>  print(locals())
>  a = eval('y')
>  print(locals())
>  y = a
>  print(y)
> f()
> {'i': 1, 'y': 42}
> 1
> {'i': 1, 'y': 1}
> {'i': 1, 'y': 42}
> {'i': 1, 'y': 42, 'a': 42}
> 42
>
> Why does this happen? No idea.
>
> I may be related with this:
>
> # test 4
> def f():
>  i = 1
>  print(locals())
>  exec('y = i; print(y); print(locals())')
>  print(locals())
>  print(y)
> f()
> Traceback (most recent call last):
> NameError: name 'y' is not defined
>
> Despite exec() adds the 'y' variable to f's locals, the variable is not
> accessible/visible from f's code.
>
> So, a few observations (by no means this is how the vm works):
>
> 1) each function has a set of variables defined by the code (let's call
> this "code-defined locals" or "cdef-locals").
> 2) each function also has a set of "runtime locals" accessible from
> locals().
> 3) exec() can add variables to locals() (runtime) set but it cannot add
> any to cdef-locals.
> 4) locals() may be a superset of cdef-locals (but entries in cdef-locals
> which value is still undefined are not shown in locals())
> 5) due rule 4, exec() cannot add a variable to locals() if it is already
>   present in the in cdef-locals.
> 6) when eval() runs, it uses locals() set for lookup
>
> Perhaps rule 5 is to prevent exec() to modify any arbitrary variable of
> the caller...
>
> Anyways, nice food for our brains.
>
> On Wed, Jul 20, 2022 at 04:56:02PM +, george trojan wrote:
> >I wish I could understand the following behaviour:
> >
> >1. This works as I expect it to work:
> >
> >def f():
> >i = 1
> >print(locals())
> >exec('y = i; print(y); print(locals())')
> >print(locals())
> >exec('y *= 2')
> >print('ok:', eval('y'))
> >f()
> >
> >{'i': 1}
> >1
> >{'i': 1, 'y': 1}
> >{'i': 1, 'y': 1}
> >ok: 2
> >
> >2. I can access the value of y with eval() too:
> >
> >def f():
> >i = 1
> >print(locals())
> >exec('y = i; print(y); print(locals())')
> >print(locals())
> >    u = eval('y')
> >print(u)
> >f()
> >
> >{'i': 1}
> >1
> >{'i': 1, 'y': 1}
> >{'i': 1, 'y': 1}
> >1
> >
> >3. When I change variable name u -> y, somehow locals() in the body of
> >the function loses an entry:
> >
> >def f():
> >i = 1
> >print(locals())
> >exec('y = i; print(y); print(locals())')
> >print(locals())
> >y = eval('y')
> >print(y)
> >f()
> >
> >{'i': 1}
> >1
> >{'i': 1, 'y': 1}
> >{'i': 1}
> >
>
> >---NameError
> >Traceback (most recent call last)
> >Input In [1], in ()  7 print(y)  8 # y
> >= eval('y')  9 #print('ok:', eval('y'))---> 10 f()
> >
> >Input In [1], in f()  4 exec('y = i; print(y); print(locals())')
> >   5 print(locals())> 6 y = eval('y')  7 print(y)
> >
> >File :1, in 
> >NameError: name 'y' is not defined1.
> >
> >Another thing: within the first exec(), the print order seems
> >reversed. What is going on?
> >
> >BTW, I am using python 3.8.13.
> >
> >George
> >--
> >https://mail.python.org/mailman/listinfo/python-list
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Download Python 3.10.6 for windows

2022-08-30 Thread George Rwaga
I last installed an updated version of python more than  a year back. I am
trying to download (from  https://www.python.org/downloads/ ) and install
Python 3.10.6 for Windows - but I keep running into problems.

1. I installed Python 3.10.6 in the default directory
C:\Users\x.x\AppData\local\programs\Python\Python310
After the installation, there was no shortcut on my desktop. I thought I
would just go to Python310 and create a shortcut. But I am unable to find
AppData.
2. I then decided to install Python3.10.6 in a customized directory
C:\program files\Python\Python310
I am being asked to verify access to this directly. I went to properties,
made what I thought were the relevant changes. But I keep getting asked to
verify access.

My R and RStudio are installed in C:\program files.

How should I proceed?

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


Re: Download Python 3.10.6 for windows

2022-08-31 Thread George Rwaga
Thanks for the suggestions, Mrab and Eryk.

Because my R and RStudio are under program files, for consistency I
installed Python in C:\program files\Python\Python310. I updated to the
latest version of Spyder in C:\program files\Spyder\Spyder5.3.3. As with R
and RStudio, some Python and Spyder files were automatically installed in
C:\Users\George.Rwaga\AppData\Local. I am not sure why the default for
installing Python
is C:\Users\x.x\AppData\local\programs\Python\Python310.

Initial tests suggest Spyder 5.3.3 is working fine. The real test will
probably come when I try to run some of my old code based on such sources
as Python for Finance by Yves Hilpisch, a book by the same title by Yuxing
Yan, Python for Data Analysis by Wes McKinney, etc.

Again, thanks.

George
--


On Tue, Aug 30, 2022 at 4:06 PM Eryk Sun  wrote:

> On 8/30/22, George Rwaga  wrote:
> >
> > 1. I installed Python 3.10.6 in the default directory
> > C:\Users\x.x\AppData\local\programs\Python\Python310
> > After the installation, there was no shortcut on my desktop.
>
> Shortcuts are created in the start menu. The installer doesn't modify
> the user's desktop or the desktop of all users, which many users don't
> want and would find annoying. Just copy the shortcuts from the start
> menu to the desktop if that's what you want. Right-click the icon in
> the start menu and choose to open the location. You can copy shortcuts
> from the opened Explorer window.
>
> > 2. I then decided to install Python3.10.6 in a customized directory
> > C:\program files\Python\Python310
> > I am being asked to verify access to this directly. I went to properties,
> > made what I thought were the relevant changes. But I keep getting asked
> to
> > verify access.
>
> Installing to "Program Files" requires elevating to get administrator
> access. All users have the right to read and execute files in a
> directory created in "Program Files", but adding, removing, or
> deleting files and directories requires administrator access, as it
> should.
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definition of "property"

2021-06-02 Thread George Fischhof
Greg Ewing  ezt írta (időpont: 2021. jún. 2.,
Sze, 4:01):

> On 1/06/21 7:01 am, Alan Gauld wrote:
> > That was the point, the OP said it was a book about OOP.
> > Not a book about "OOP in Python".
>
> In that case it would be best to avoid the word, or give
> a definition of the way he's using it, making it clear
> that it's not a universal definition. Python's definition
> is somewhat unusual, and so would not be appropriate.
>
> --
> Greg
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


Hi,

I think in OOP point of view one can write that property is the python
implementation of the OOP concepts:
Encapsulation and Information hiding

Some explanation for beginners on these paradigms:
https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making command-line args available to deeply-nested functions

2021-08-21 Thread George Fischhof
Loris Bennett  ezt írta (időpont: 2021. aug.
20., P 17:54):

> Julio Di Egidio  writes:
>
> > On Friday, 20 August 2021 at 11:54:00 UTC+2, Loris Bennett wrote:
> >> Hi,
> >>
> >> TL;DR:
> >>
> >> If I have a command-line argument for a program, what is the best way
> >> of making this available to a deeply-nested[1] function call without
> >> passing the parameter through every intermediate function?
> >
> > To not pass arguments you need shared state ("global variables"): and
> > options in shard state, unless you have very good reasons to do
> > otherwise, is simply a no no.
>
> Doesn't that slightly depend on the size of your "globe"?  If a program
> does a few, in some sense unrelated things, and, say, only runs for a
> few minutes, could you not decide to make a particular parameter global,
> even though only one function needs it?  In general, however, I would
> also avoid this.
>
> > 
> >> I can see that the top-level could just create an object from a class
> >> which encapsulates everything, but what if I want to keep the salutation
> >> generation separate, so that I can have a separate program which just
> >> generates the salutation and print it to the terminal?
> >
> > Yes, that's basically the way to go: parse arguments into a structure (an
> > object) that contains all options/parameters then pass that down.  Next
> level:
> > some sections of your code may require a certain subset of those
> options, some
> > may require some other, so you would structure your options object in
> > sub-objects for the various sets of correlated options, then rather pass
> just
> > the sub-object(s) that are relevant to the section of code you are
> calling.
> > Variations are of course possible, anyway that's the basic idea.
> >
> > Also have a look at the "argparse" library, it does all the heavy
> lifting for
> > the parsing and creation of those objects, definitely advised for in non
> trivial
> > cases: <https://docs.python.org/3/library/argparse.html>.
>
> I am already using 'argparse' ('configargparse' actually).  What aspect
> should I be looking at in order to produce "sub-objects"?
>
> >> I guess I am really asking how to avoid "passing through" arguments to
> >> functions which only need them to call other functions, so maybe the
> >> answer is just to avoid nesting.
> >
> > No, you don't get rid of code structure just not to pass arguments to
> > a function...  Code may be poorly structured, but that's another
> > story.
>
> As I am writing new code it is more a question of imposing structure,
> rather than getting rid of structure.  Unwritten code for a given
> purpose obviously has some sort of structure with regards to, say, loops
> and conditions, but I am less sure about the implications for how the
> code should be nested.  Another argument against deeply-nested functions
> is the increased complexity of testing.
>
> Cheers,
>
> Loris
>
> --
> This signature is currently under construction.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

>
>
>


Hi,

Also you can give a try to click and / or  typer packages.
Putting args into environment variables can be a solution too
All of these depends on several things: personal preferences, colleagues /
firm standards, the program, readability, variable accessibility (IDE
support, auto completition) (env vars not supported by IDEs as they are not
part of code)

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making command-line args available to deeply-nested functions

2021-08-23 Thread George Fischhof
Loris Bennett  ezt írta (időpont: 2021. aug.
23., H 19:26):

> George Fischhof  writes:
>
> > Loris Bennett  ezt írta (időpont: 2021. aug.
> > 20., P 17:54):
> >
> >> Julio Di Egidio  writes:
> >>
> >> > On Friday, 20 August 2021 at 11:54:00 UTC+2, Loris Bennett wrote:
> >> >> Hi,
> >> >>
> >> >> TL;DR:
> >> >>
> >> >> If I have a command-line argument for a program, what is the best way
> >> >> of making this available to a deeply-nested[1] function call without
> >> >> passing the parameter through every intermediate function?
> >> >
> >> > To not pass arguments you need shared state ("global variables"): and
> >> > options in shard state, unless you have very good reasons to do
> >> > otherwise, is simply a no no.
> >>
> >> Doesn't that slightly depend on the size of your "globe"?  If a program
> >> does a few, in some sense unrelated things, and, say, only runs for a
> >> few minutes, could you not decide to make a particular parameter global,
> >> even though only one function needs it?  In general, however, I would
> >> also avoid this.
> >>
> >> > 
> >> >> I can see that the top-level could just create an object from a class
> >> >> which encapsulates everything, but what if I want to keep the
> salutation
> >> >> generation separate, so that I can have a separate program which just
> >> >> generates the salutation and print it to the terminal?
> >> >
> >> > Yes, that's basically the way to go: parse arguments into a structure
> (an
> >> > object) that contains all options/parameters then pass that down.
> Next
> >> level:
> >> > some sections of your code may require a certain subset of those
> >> options, some
> >> > may require some other, so you would structure your options object in
> >> > sub-objects for the various sets of correlated options, then rather
> pass
> >> just
> >> > the sub-object(s) that are relevant to the section of code you are
> >> calling.
> >> > Variations are of course possible, anyway that's the basic idea.
> >> >
> >> > Also have a look at the "argparse" library, it does all the heavy
> >> lifting for
> >> > the parsing and creation of those objects, definitely advised for in
> non
> >> trivial
> >> > cases: <https://docs.python.org/3/library/argparse.html>.
> >>
> >> I am already using 'argparse' ('configargparse' actually).  What aspect
> >> should I be looking at in order to produce "sub-objects"?
> >>
> >> >> I guess I am really asking how to avoid "passing through" arguments
> to
> >> >> functions which only need them to call other functions, so maybe the
> >> >> answer is just to avoid nesting.
> >> >
> >> > No, you don't get rid of code structure just not to pass arguments to
> >> > a function...  Code may be poorly structured, but that's another
> >> > story.
> >>
> >> As I am writing new code it is more a question of imposing structure,
> >> rather than getting rid of structure.  Unwritten code for a given
> >> purpose obviously has some sort of structure with regards to, say, loops
> >> and conditions, but I am less sure about the implications for how the
> >> code should be nested.  Another argument against deeply-nested functions
> >> is the increased complexity of testing.
>
> [snip (15 lines)]>
>
> > Hi,
> >
> > Also you can give a try to click and / or  typer packages.
> > Putting args into environment variables can be a solution too
> > All of these depends on several things: personal preferences, colleagues
> /
> > firm standards, the program, readability, variable accessibility (IDE
> > support, auto completition) (env vars not supported by IDEs as they are
> not
> > part of code)
>
> Thanks for the pointers, although I have only just got my head around
> argparse/configargparse, so click is something I might have a look at
> for future project.
>
> However, the question of how to parse the arguments is somewhat separate
> from that of how to pass (or not pass) the arguments around within a
> program.
>
> Cheers,
>
> Loris
>
> --
> This signature is currently under construction.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

>
>
>



Hi,
I thought not just parsing, but the usage method: you add a decorator to
the function where you want to use the parameters. This way you do not have
to pass the value through the calling hierarchy.

Note: typer is a newer package, it contains click and leverages command
line parsing even more.


BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making command-line args available to deeply-nested functions

2021-08-29 Thread George Fischhof
Loris Bennett  ezt írta (időpont: 2021. aug.
26., Cs, 16:02):

> George Fischhof  writes:
>
> [snip (79 lines)]
>
> >> > Hi,
> >> >
> >> > Also you can give a try to click and / or  typer packages.
> >> > Putting args into environment variables can be a solution too
> >> > All of these depends on several things: personal preferences,
> colleagues
> >> /
> >> > firm standards, the program, readability, variable accessibility (IDE
> >> > support, auto completition) (env vars not supported by IDEs as they
> are
> >> not
> >> > part of code)
> >>
> >> Thanks for the pointers, although I have only just got my head around
> >> argparse/configargparse, so click is something I might have a look at
> >> for future project.
> >>
> >> However, the question of how to parse the arguments is somewhat separate
> >> from that of how to pass (or not pass) the arguments around within a
> >> program.
>
> [snip (16 lines)]
> >
> > Hi,
> > I thought not just parsing, but the usage method: you add a decorator to
> > the function where you want to use the parameters. This way you do not
> have
> > to pass the value through the calling hierarchy.
> >
> > Note: typer is a newer package, it contains click and leverages command
> > line parsing even more.
>
> Do you have an example of how this is done?  From a cursory reading of
> the documentation, it didn't seem obvious to me how to do this, but then
> I don't have much understanding of how decorators work.
>
> Cheers,
>
> Loris
>
>
> --
> This signature is currently under construction.
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi,

will create a sample code on Monday - Tuesday

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making command-line args available to deeply-nested functions

2021-08-31 Thread George Fischhof
George Fischhof  ezt írta (időpont: 2021. aug. 29., V,
21:27):

>
>
> Loris Bennett  ezt írta (időpont: 2021. aug.
> 26., Cs, 16:02):
>
>> George Fischhof  writes:
>>
>> [snip (79 lines)]
>>
>> >> > Hi,
>> >> >
>> >> > Also you can give a try to click and / or  typer packages.
>> >> > Putting args into environment variables can be a solution too
>> >> > All of these depends on several things: personal preferences,
>> colleagues
>> >> /
>> >> > firm standards, the program, readability, variable accessibility (IDE
>> >> > support, auto completition) (env vars not supported by IDEs as they
>> are
>> >> not
>> >> > part of code)
>> >>
>> >> Thanks for the pointers, although I have only just got my head around
>> >> argparse/configargparse, so click is something I might have a look at
>> >> for future project.
>> >>
>> >> However, the question of how to parse the arguments is somewhat
>> separate
>> >> from that of how to pass (or not pass) the arguments around within a
>> >> program.
>>
>> [snip (16 lines)]
>> >
>> > Hi,
>> > I thought not just parsing, but the usage method: you add a decorator to
>> > the function where you want to use the parameters. This way you do not
>> have
>> > to pass the value through the calling hierarchy.
>> >
>> > Note: typer is a newer package, it contains click and leverages command
>> > line parsing even more.
>>
>> Do you have an example of how this is done?  From a cursory reading of
>> the documentation, it didn't seem obvious to me how to do this, but then
>> I don't have much understanding of how decorators work.
>>
>> Cheers,
>>
>> Loris
>>
>>
>> --
>> This signature is currently under construction.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>
> Hi,
>
> will create a sample code on Monday - Tuesday
>
> BR,
> George
>


Hi,

here is the program ;-) (see below)
typer does not uses decorators, to solve this problem they advice to use
click's decorators, mixing typer and click.
Practically I prefer not to mix them, also the parts for easiest way to do
this just available in latest click, which is not supported in typer.

So I created all the stuff in click, 8.x should be used

BR,
George


import click


# read command line parameters
@click.command()
@click.option('--level_1', help='Level 1')
@click.option('--level_2', help='Level 2')
def main(level_1, level_2):
# put command line parameters into global context
ctx = click.get_current_context()
ctx.meta['level_1'] = level_1
ctx.meta['level_2'] = level_2

level_1_function()


# pass / inject level_1 parameter to this function
@click.decorators.pass_meta_key('level_1')
def level_1_function(level_1):
print(f'level 1 variable: {level_1}')
level_2_function()


# pass / inject level_2 parameter to this function
@click.decorators.pass_meta_key('level_2')
def level_2_function(level_2):
print(f'level 2 variable: {level_2}')


if __name__ == "__main__":
main()
-- 
https://mail.python.org/mailman/listinfo/python-list


GPG signatures invisible in new PyPI (was: Re: new Python Package Index is now in beta at pypi.org)

2018-03-31 Thread Dominik George
Hi,

On Sat, Mar 31, 2018 at 06:16:51PM -0400, Sumana Harihareswara wrote:
> The new Python Package Index at https://pypi.org is now in beta.

Yep!

I read that the new Warehouse does not offer GPG signature files for
download.

Why not?  How can I still get them (append .asc to the source downlaod?),
and how do I find out whether an upload is signed?

I am asking mainly as a Debian developer relying on upstream signatures.

-nik

-- 
PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296

Dominik George · Hundeshagenstr. 26 · 53225 Bonn
Phone: +49 228 92934581 · https://www.dominik-george.de/

Teckids e.V. · FrOSCon e.V. · Debian Developer

LPIC-3 Linux Enterprise Professional (Security)


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GPG signatures invisible in new PyPI (was: Re: new Python Package Index is now in beta at pypi.org)

2018-03-31 Thread Dominik George
Hi Sumana,

> I've been trying to reach out to the Debian Python community via IRC,
> personal connections, tickets, and mailing lists to ensure a smooth
> transition; I see now that a post I tried to get onto the debian-python
> list a few weeks ago did not get posted there, so I've re-sent it. I'm
> sorry that this is (I infer) the first you're hearing about this change.

Thank you ☺!

I see that the discussion there now has started.

Cheers,
Nik


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add values from test steps in pytest excel report

2018-04-30 Thread George Fischhof
On 27 Apr 2018 9:49 am, "Sum"  wrote:

Hi,

I am using python 2.7 and pytest version 3.2.1
I am using pytest excel plugin to run the pytest and generate test report
in excel format.

Step to install pytest excel : pip install pytest-excel

I am running my pytest test using below :

py.test --excelreport=report.xls e_test.py

Output Test report excel format :

SUITE NAME  TEST NAME   DESCRIPTION RESULT  DURATIONMESSAGE FILE
NAME   MARKERSTestSumFlow test_step1  PASSED  15.24737811
e_test.py

My query is that I want to display the values from my corresponding test
steps in pytest.
e.g. if my test step is following, then how do I display the output of
test_step1 "newNum" in the excel report.

def test_step1(fNum, sNum):
newNum = fNum - sNum
print newNum


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



Hi Sumit,

You should use assert for testing:
assert new_num == f_num - s_num, "Message if assert is false"

or if you want to use more checking, you should use pytest.assume plugin.

If you just want to write something to output, you should use logging, here
are some info about logging in pytest:
https://docs.pytest.org/en/latest/logging.html


BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flask test generator code review?

2018-04-30 Thread George Fischhof
2018-04-18 12:41 GMT+02:00 Albert-Jan Roskam :

> Hi,
>
> I am writing my first unittests for a Flask app. First modest goal is to
> test whether a selected subset of the templates return the expected status
> 200.
> I am using a nose test generator in a class for this. Is the code below
> the correct way to do this? And is there a way to dynamically set the
> docstring of test_generator? This would make the nosetests output a bit
> more understandable.
>
> Thanks!
> Albert-Jan
>
> import os
> import sys
> from os.path import splitext
> from http import HTTPStatus as status
>
> import nose
>
> from MyFabulousApp import app
>
> app.testing = True
> template_folder = app.config['TEMPLATE_FOLDER']
>
>
> class Test_MyFabulousApp_HTTP_Status_OK:
>
> def __init__(self):
> self.setup()   # with unittest, setUp is called automatically, but
> not with nose
>
> def setup(self):
> self.client = app.test_client()
> self.client.post('/login', follow_redirects=True)
>
> def teardown(self):
> self.client.post('/logout', follow_redirects=True)
>
> def test_generator(self):
> """Does template return HTTP Status 200?"""
> def the_test(self, template):
> # the following line throws an error: AttributeError:
> attribute '__doc__' of 'method' objects is not writable
> #self.test_generator.__doc__ = 'Does template "%s" return HTTP
> Status 200?' % template
> respons = self.client.get('/' + template)
> actual = respons.status_code
> desired = status.OK.value
> assert actual == desired, \
>'Template "%s" returns status code %d' % (template, actual)
> templates = [splitext(item)[0] for item in
> os.listdir(template_folder)]
> for template in templates:
> yield the_test, self, template
>
>
> if __name__ == '__main__':
> nose.run(defaultTest=__name__, argv=[sys.argv[0], '__main__',
> '--verbosity=2'])
> --
> https://mail.python.org/mailman/listinfo/python-list
>


Hi,

maybe you should check PyTest
https://docs.pytest.org/en/latest/

and Flas testing turorial:
http://flask.pocoo.org/docs/1.0/testing/


BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unittest.Testsuite and execution order

2018-04-30 Thread George Fischhof
On 20 Apr 2018 8:39 am, "Chris Angelico"  wrote:

On Fri, Apr 20, 2018 at 3:01 PM, Francesco Russo 
wrote:
> On 18/04/18 20:26, Chris Angelico wrote:
>> This is a bad idea. Each function that starts test_ should be
>> completely independent. You should be able to run any one of them on
>> its own (say, if you're trying to figure out why your latest change
>> caused a test failure), and it should have the same result.
>>
>> Make it so that test_func_1 and test_func_2 are completely
>> independent, and then, if you need a single test that uses both, have
>> a test that calls on each function.
>
> I'm not sure I understand you here.
> I understood that (besides, or instead of, making an integration test by
> making those tests into one test, as you wrote above) I could make a
> test for func_2 making it independent from func_1, for example this way:
>
> class MyTestFunc2(unittest.TestCase):
>def setUp(self):
>   # Prepare preconditions for func_2
>
>def test_func_2(self):
>   sut.func_2()
>   self.assert(...)
>
> Such a test case wouldn't even need a test suite.
> Is this what you meant?

What I mean is that test_func_1 and test_func_2 should be able to pass
or fail regardless of whether the other has been run or not. That kind
of independence. If you then want to write an integration test that
verifies that data created by func_1 can be read by func_2, that is a
separate test.

> The official "unittest" web pages for Python 2 and 3 say this, for the
> TestSuite class:
> *This class represents an aggregation of individual tests cases and test
> suites*
> saying nothing about the order. But the docstring of the TestSuite class
> says:
> *It will run the individual test cases in the order in which they were
> added, aggregating the results*
> Can I consider the docstring an official documentation as well?
>

That's something for other people to answer; I don't know whether
TestSuite is a replaceable class. I'm not sure what the mechanics are
for test randomization, but it is most definitely a thing.

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



Hi,

If you want to use more asserts in a test case, you should use
pytest-assume plugin.

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


[ANN] pluggable-info-monitor 0.2.1 released!

2018-05-29 Thread George Fischhof
Hi everyone,

I’m very excited to announce the release of pluggable-info-monitor 0.2.1
First public release.

You can download it form bitbucket:
https://bitbucket.org/GeorgeFischhof/pluggable_info_monitor

package index page:
https://pypi.python.org/pypi/pluggable-info-monitor


What is pluggable-info-monitor?

A web application that shows the information you gathered with your plugin.
It can be anything ;-) examples:
- in a development environment, bug statistics, build and test results
- in education, some education material
- in an office it can show the weather foreast, namedays, daily quotes
- it can be used as a dashboard for system administrators
- etc

There are example plugins to help developing your own plugins.


Please note:

The full feature set requires Python 3.4 and later.



Have fun using pluggable-info-monitor
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: command line utility for cups

2018-06-20 Thread George Fischhof
Peter Otten <__pete...@web.de> ezt írta (időpont: 2018. jún. 20., Sze
12:22):

> Brian Oney via Python-list wrote:
>
> > Dear all,
> >
> > I am having trouble with argparse. I am trying to translate the following
> > line to a sleek python script:
> >
> > lpr -o media=legal -o sides=two-sided-long-edge filename
> >
> > Now where I am.
> >
> > import argparse
> > parser = argparse.ArgumentParser(description='Print stuff with cups')
> > parser.add_argument('--printer', '-p',
> > help='Use this printer, try running: lpstat -a')
> > parser.add_argument('--options', '-o',
> > help='Options for this printer, try running: \
> > lpoptions -p PRINTER -l')
> >
> > parser.parse_known_args(['-o', 'sides=one-sided', '-o', 'test=crap'])
> > Namespace(options='test=crap', printer=None))
> >
> > How should I deal with multiple options being fed into my script?
> >
> > Thanks!
>
> Try action="append". You may also provide a type=split_func argument to
> split the key=value pairs:
>
> >>> import argparse
> >>> parser = argparse.ArgumentParser()
> >>> parser.add_argument("-o", action="append", type=lambda p: p.split("=",
> 1))
> _AppendAction(option_strings=['-o'], dest='o', nargs=None, const=None,
> default=None, type= at 0x7feef70a8510>, choices=None,
> help=None, metavar=None)
> >>> parser.parse_args(["-o", "a=b", "-o", "c=d"])
> Namespace(o=[['a', 'b'], ['c', 'd']])
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



Hi,
You can also try click library from pypi, that is a very good command line
stuff.

George

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


Re: translating foreign data

2018-06-21 Thread George Fischhof
Peter Otten <__pete...@web.de> ezt írta (időpont: 2018. jún. 21., Cs,
22:45):

> Ethan Furman wrote:
>
> > I need to translate numeric data in a string format into a binary
> format.
> > I know there are at least two different
> > methods of representing parts less that 1, such as "10.5" and "10,5".
> The
> > data is encoded using code pages, and can vary depending on the file
> being
> > read (so I can't rely on current locale settings).
> >
> > I'm sure this is a solved problem, but I'm not finding those solutions.
> > Any pointers?
>
> There's babel
>
> http://babel.pocoo.org/en/latest/numbers.html#parsing-numbers
>
> though I'm not sure what to think of the note below the linked paragraph.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi,

if you have several values in a file, then you probably you can check the
delimiters: there is only one decimal separator,
- so if you find a number with 2 separators, then a rightmost is a the
decimal
- if you found only one type, then that is the decimal
- try to check the separator from right to left
- if you found 4 digits right to a separator, then that is the decimal
separator
etc (maybe wikipedia should be checked for other separators.
Other thousand separators used: space, apostrophe, and in India after the
first thousand separator the separation is done with two numbers, not three

And if you are able to identify the encoding codepage, then you should
follow what the codepage says

Another help can be if know the possible value range of the numbers (maybe
it should be asked ...)


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


Re: how to get a value from CSV specific cell (A7) thanks

2018-09-01 Thread George Fischhof
HI,

CSV has no cells, but you can use csv module from standard lib
https://docs.python.org/3/library/csv.html
and you can get 7th data from the first row (as A means the first row)

__george__

 ezt írta (időpont: 2018. szept. 1., Szo, 20:24):

> how to get a value from CSV specific cell (A7) thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python for System Verilog testbench

2018-09-13 Thread George Fischhof
Bobby  ezt írta (időpont: 2018. szept. 14., P
0:16):

>
> I have a very simple System Verilog (SV) adder as my DUT (device under
> test). I would like to  generate a test bench for this DUT based on the
> 'requirements'. I wrote its  (DUT) functions in simple text as
> 'requirements' while following a particular syntax. Now through  the help
> of grammar, I would like to give the requirement input to the grammar.
>
> Questions:
>
>  (1) Considering my end goal, i.e. to generate some particular parts
> of
>  SV testbench from requirements, any good python parser available
> ?
>
>  (2) If I use python parser, will any kind of python scripting will
> help me to generate the testbench in SV for my DUT ? My confusion at this
> point is that most of all the literature I am reading suggests linguistic
> techniques. Any non-linguistic technique ?
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



Hi,

Perhaps you should check articles about BDD,  and you can use PyTest test
framework with pytest-bdd plugin

__george__

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


How to make sphinx to recognize functools.partial?

2016-04-03 Thread George Trojan

Yet another sphinx question. I am a beginner here.

I can't make sphinx to recognize the following (abbreviated) code:

'''
module description

:func:`~pipe` and :func:`~spipe` read data passed by LDM's `pqact`.

'''

def _pipe(f, *args):
'''doc string'''
 pass

def _get_msg_spipe():
'''another doc'''
 pass

spipe = functools.partial(_pipe, _get_msg_spipe)
spipe._doc_ = '''
Loop over data feed on `stdin` from LDM via SPIPE.
'''

The word spipe is rendered correctly in html, but the link is not created.

I did put a print statement in sphinx/util/inspect.py, it appears that 
spipe definition is not recognized. I am running sphinx 1.3.5, according 
to CHANGELOG functools.partial support was added in 1.2.1.


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


TypeError: unorderable types: function() < int()

2016-05-10 Thread George Molsom
I have created a program in class 'make a game that tests how good people are 
at guessing when 10 seconds has elapsed.'

The following are the code I currently have and the error produced when I 
attempt to run it. I have tried everything I can think of to resolve the issue, 
and I have also run the code through a checker, which has said that there are 
no mistakes. I have also shown a friend who is a programmer, and he cannot find 
a problem with it. The teacher doesn't actually know the solution to the 
problem so I was wondering if someone could point me in the right direction to 
get this working please?



import time

def second(int):
time.strftime("%S")

start = input('Press enter when you are ready to start')
time1 = time.strftime("%S")

then = time.time()

end = input('Press enter when you think 10 seconds has passed')
time2 = time.strftime("%S")

def totaltime(int):
(time2-time1)

if totaltime == '10':
print ('YOU ACTUALLY DID IT')

if totaltime < 10:
print ('Haha you took too long! Your result was:', totaltime,'seconds')

if totaltime > 10:
print('Too early TRY AGAIN! Your result was:', totaltime, 'seconds')





Press enter when you are ready to start
Press enter when you think 10 seconds has passed
Traceback (most recent call last):
  File "E:/Computing/Python/Little book of challenges/Challenge 6 10 seconds 
experiment.py", line 20, in 
if totaltime < 10:
TypeError: unorderable types: function() < int()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing performance question

2019-02-20 Thread george trojan
def create_box(x_y):
return geometry.box(x_y[0] - 1, x_y[1],  x_y[0], x_y[1] - 1)

x_range = range(1, 1001)
y_range = range(1, 801)
x_y_range = list(itertools.product(x_range, y_range))

grid = list(map(create_box, x_y_range))

Which creates and populates an 800x1000 “grid” (represented as a flat list
at this point) of “boxes”, where a box is a shapely.geometry.box(). This
takes about 10 seconds to run.

Looking at this, I am thinking it would lend itself well to
parallelization. Since the box at each “coordinate" is independent of all
others, it seems I should be able to simply split the list up into chunks
and process each chunk in parallel on a separate core. To that end, I
created a multiprocessing pool:

pool = multiprocessing.Pool()

And then called pool.map() rather than just “map”. Somewhat to my surprise,
the execution time was virtually identical. Given the simplicity of my
code, and the presumable ease with which it should be able to be
parallelized, what could explain why the performance did not improve at all
when moving from the single-process map() to the multiprocess map()?

I am aware that in python3, the map function doesn’t actually produce a
result until needed, but that’s why I wrapped everything in calls to
list(), at least for testing.


The reason multiprocessing does not speed things up is the overhead of
pickling/unpickling objects. Here are results on my machine, running
Jupyter notebook:

def create_box(xy):
return geometry.box(xy[0]-1, xy[1], xy[0], xy[1]-1)

nx = 1000
ny = 800
xrange = range(1, nx+1)
yrange = range(1, ny+1)
xyrange = list(itertools.product(xrange, yrange))

%%time
grid1 = list(map(create_box, xyrange))

CPU times: user 9.88 s, sys: 2.09 s, total: 12 s
Wall time: 10 s

%%time
pool = multiprocessing.Pool()
grid2 = list(pool.map(create_box, xyrange))

CPU times: user 8.48 s, sys: 1.39 s, total: 9.87 s
Wall time: 10.6 s

Results exactly as yours. To see what is going on, I rolled out my own
chunking that allowed me to add some print statements.

%%time
def myfun(chunk):
g = list(map(create_box, chunk))
print('chunk', chunk[0], datetime.now().isoformat())
return g

pool = multiprocessing.Pool()
chunks = [xyrange[i:i+100*ny] for i in range(0, nx*ny, 100*ny)]
print('starting', datetime.now().isoformat())
gridlist = list(pool.map(myfun, chunks))
grid3 = list(itertools.chain(*gridlist))
print('done', datetime.now().isoformat())

starting 2019-02-20T23:03:50.883180
chunk (1, 1) 2019-02-20T23:03:51.674046
chunk (701, 1) 2019-02-20T23:03:51.748765
chunk (201, 1) 2019-02-20T23:03:51.772458
chunk (401, 1) 2019-02-20T23:03:51.798917
chunk (601, 1) 2019-02-20T23:03:51.805113
chunk (501, 1) 2019-02-20T23:03:51.807163
chunk (301, 1) 2019-02-20T23:03:51.818911
chunk (801, 1) 2019-02-20T23:03:51.974715
chunk (101, 1) 2019-02-20T23:03:52.086421
chunk (901, 1) 2019-02-20T23:03:52.692573
done 2019-02-20T23:04:02.477317
CPU times: user 8.4 s, sys: 1.7 s, total: 10.1 s
Wall time: 12.9 s

All ten subprocesses finished within 2 seconds. It took about 10 seconds to
get back and assemble the partial results. The objects have to be packed,
sent through network and unpacked. Unpacking is done by the main (i.e.
single) process. This takes almost the same time as creating the objects
from scratch. Essentially the process does the following:

%%time
def f(b):
g1 = b[0].__new__(b[0])
g1.__setstate__(b[2])
return g1
buf = [g.__reduce__() for g in grid1]
grid4 = [f(b) for b in buf]

CPU times: user 20 s, sys: 411 ms, total: 20.4 s
Wall time: 20.3 s

The first line creates the pickle (not exactly, as pickled data is a single
string, not a list). The second line is what pickle.loads() does.

I do not think numpy will help here. The Python function box() has to be
called 800k times. This will take time. np.vectorize(), as the
documentation states, is provided only for convenience, it is implemented
with a for loop. IMO vectorization would have to be done on C level.

Greetings from Anchorage

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


Re: Multiprocessing performance question

2019-02-20 Thread george trojan
I don't know whether this is a toy example, having grid of this size is not
uncommon. True, it would make more sense to do distribute more work on each
box, if there was any. One has to find a proper balance, as with many other
things in life. I simply  responded to a question by the OP.

George

On Thu, 21 Feb 2019 at 01:30, DL Neil 
wrote:

> George
>
> On 21/02/19 1:15 PM, george trojan wrote:
> > def create_box(x_y):
> >  return geometry.box(x_y[0] - 1, x_y[1],  x_y[0], x_y[1] - 1)
> >
> > x_range = range(1, 1001)
> > y_range = range(1, 801)
> > x_y_range = list(itertools.product(x_range, y_range))
> >
> > grid = list(map(create_box, x_y_range))
> >
> > Which creates and populates an 800x1000 “grid” (represented as a flat
> list
> > at this point) of “boxes”, where a box is a shapely.geometry.box(). This
> > takes about 10 seconds to run.
> >
> > Looking at this, I am thinking it would lend itself well to
> > parallelization. Since the box at each “coordinate" is independent of all
> > others, it seems I should be able to simply split the list up into chunks
> > and process each chunk in parallel on a separate core. To that end, I
> > created a multiprocessing pool:
>
>
> I recall a similar discussion when folk were being encouraged to move
> away from monolithic and straight-line processing to modular functions -
> it is more (CPU-time) efficient to run in a straight line; than it is to
> repeatedly call, set-up, execute, and return-from a function or
> sub-routine! ie there is an over-head to many/all constructs!
>
> Isn't the 'problem' that it is a 'toy example'? That the amount of
> computing within each parallel process is small in relation to the
> inherent 'overhead'.
>
> Thus, if the code performed a reasonable analytical task within each box
> after it had been defined (increased CPU load), would you then notice
> the expected difference between the single- and multi-process
> implementations?
>
>
>
>  From AKL to AK
> --
> Regards =dn
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mocking for get method in requests

2019-03-16 Thread George Fischhof
Shakti Kumar  ezt írta (időpont: 2019. jan.
18., P, 18:18):

> Hello people,
> I noticed something weird (weird as per my current knowledge, though I know
> its subjective) today.
>
> sample.py file
>
> --
>
> import requests
> def random_testing():
> out = requests.get('www.cisco.com')
> a = out.json()
> return a
>
>
> testing.py file
>
> --
>
> @patch(*’*sample.requests')
> def test_random_testing(self, mock_req):
> mock_req.get('').return_value = 'Hello'
> out = api.random_testing()
>
>
> Patching the sample.requests in this way does not lead the output of
> requests.get() function in sample.py file to be ‘Hello’ as indicated
> in
> mock_req.get('').return_value = 'Hello'
> Instead, it creates a new field called return_value in ‘out', and
> hence out.return_value is ‘Hello’ instead of just ‘out’.
>
> But if I patch it as,
>
> @patch(*’*sample.requests')
> def test_random_testing(self, mock_req):
> mock_req.get.return_value = 'Hello'
> out = api.random_testing()
>
> It does give the value of ‘out’ as ‘Hello’ in sample.py file.
> I know I am missing something, which is where I need some help :)
>
> Thanks.
>
> --
>
>
> 
> UG, CSE,
> RVCE, Bengaluru.
> --
> https://mail.python.org/mailman/listinfo/python-list



Hi  Kumar,

I saw that there was no answer.
Perhaps you should check PyTest
https://docs.pytest.org/en/latest/contents.html
it has several plugins, it can mock, and can do much things.

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot a data including date and time?

2019-08-14 Thread George Fischhof
Elliott Roper  ezt írta (időpont: 2019. aug. 14., Sze
15:56):

> On 14 Aug 2019, Elliott Roper wrote
> (in article<0001hw.23044901039e772c7ca97...@news.giganews.com>):
>
> > On 14 Aug 2019, amirrezaheidary...@gmail.com wrote
> > (in article<23d45668-fa47-4640-832a-5a5c64600...@googlegroups.com>):
> >
> > > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2,
> amirrezah...@gmail.com
> > > wrote:
>
> Oh Damn! Here is an attempt to stop the code running into a single line..
> > >
> > > > I have a .csv file, in first column I have date and hour, and in the
> second
> > > > column I have energy use data. How can I make a bar chart with Date
> and
> > > > time as the x axis and the energy use as the Y axis?
> > > >
> > > > Thanks
> > >
> > > Thank you for your guidance. I am already using matplotlib but I do
> not know
> > > how to import a column of date and time and to use it properly as the x
> > > axis.
> > > can you tell me the code?
> > >
> > > Thanks
>
> >
> > If you don't mind using a steam hammer to crack a nut, it is amazing
> what you
> > can do with pandas using just the "10 minute guide" chapter in the
> (shudder)
> > 10,000 page manual. The chief benefit is how thoroughly it protects you
> from
> > Numpy and Matplotlib.
> > I solved a similar problem (tracking home blood pressure with
> exponentially
> > weighted means) up and running in half a day from a completely cold
> start.
> > The graphing bit is a delight. However, if you want to do something that
> the
> > 10 minute guide does not cover, you can lose a man-month without really
> > trying. Pandas is a beautiful monster!
> >
> > Here's the relevant bit
> >
> > import numpy as np
> >
> > import pandas as pd
> >
> > import matplotlib.pyplot as plt
> >
> >
> > #preparing the csv from a text file elided as irrelevant
> >
> > #except that the .csv headings have to be Date Systolic Diastolic for
> this to
> > work as designed
> >
> > # Plot the intermediate file with pandas after adding exponentially
> weighted
> > means
> >
> > df = pd.read_csv('Blood pressure.csv')
> >
> > df['Date'] = pd.to_datetime(df['Date'])
> >
> > df['Syst EWM'] = df['Systolic'].ewm(span=200).mean()
> >
> > df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean()
> >
> > plt.ioff()
> >
> > df.plot(x='Date')
> >
> > print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more
> > healthy levels
> >
> > plt.ylabel('mm Hg')
> >
> > plt.suptitle("Home BP record")
> >
> > plt.show()
> >
> > That should give you a start
>
> --
> To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96
> 3CF7
> 637F 896B C810 E199 7E5C A9E4 8E59 E248
>
> --
> https://mail.python.org/mailman/listinfo/python-list




Hi,

Pygal is a very good and easy to use charting library

BR,
George


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


Re: What do you use for slides?

2019-11-16 Thread George Fischhof
Dan Stromberg  ezt írta (időpont: 2019. nov. 15., P,
22:36):

> I mostly use Libreoffice Impress, but I've also tried Google Slides.
>
> I don't think Impress does syntax highlighting out of the box, but there's
> a plugin that claims to.
>
> Also, Google Slides purportedly supports highlighting just by
> cut-and-pasting from a GUI editor/IDE with syntax highlighting.
>
> HTH.
>
> On Fri, Nov 15, 2019 at 9:38 AM Abdur-Rahmaan Janhangeer <
> arj.pyt...@gmail.com> wrote:
>
> > Greetings all,
> >
> > For slides i use https://yhatt.github.io/marp/, but sometimes i want a
> > more
> > stylish tool.
> >
> > What do you use for slides? (besides powerpoint + syntax highlighting
> > included)
> >
> > Thanks!
> >
> > Abdur-Rahmaan Janhangeer
> > http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ
> > Mauritius
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi
I use Google drive's slides, plus  https://revealjs.com/

br,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Managing plug-ins

2020-05-27 Thread George Fischhof
DL Neil via Python-list  ezt írta (időpont: 2020.
máj. 26., K, 3:10):

> On 26/05/20 11:35 AM, Benjamin Schollnick wrote:
> > Did you ever find anything that met your requirements?
> >
> > If not, I have a prototype that I need to build out some more…
> >
> > https://github.com/bschollnick/PyPlugInMgr
> >
> > I use it for some home grown utilities, but it needs to be fleshed out
> > some more…
> > If you’re interested feel free to take a look.
>
> Thanks.
> Am on-the-road at present, but will take a look...
> --
> Regards =dn
> --
> https://mail.python.org/mailman/listinfo/python-list


HI,

I do not understand your requirements fully, but two easy come to mind:
registering function as plugin - you can find metaclass or functional
programing examples in google; keywords: register plugin

And the second one, is to put files to a given place and import them in
runtime, I created a pluggable info monitor which does this: in every
cycles imports the given files as plugins.
https://pypi.org/project/pluggable-info-monitor/

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-authors] Query

2021-01-11 Thread George Fischhof
Eduardo Emén Muñoz  ezt írta (időpont: 2021. jan. 8.,
P, 17:23):

> Dear Srs,
>
>  I apologize if this is not the right place to ask this question, I am
> Biologist teaching Python language (in spanish)  focused in Molecular
> Biology.
>
>  People interested often ask me if my classes/course has a valid
> certification and I have to say no, so my question is :
>
> What can I do for provide a valid diploma with the Python logo to my
> students? I mean, how I would be allowed to give a valid
> Python logo on my students diploma? I have tried to contact local
> institutions like Biology's college, Education Ministry , etc but no
> success at all.
>
> Many thanks for your time reading this email, sorry for my poor english
> and thanks in advance.
>
>
> ___
> Python-authors mailing list
> python-auth...@python.org
> https://mail.python.org/mailman/listinfo/python-authors


Hi,

the good forum for similar questions is  python-list@python.org mail list -
I think ;-)

Right _now_ Microsoft created a Python exam, I do not know how much is that
appreciated, or accepted, but there is.
As I know this is the only one somewhat standardised exam now.
Of course there are several institutes holding Python course and exam

BR,
George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show percentage

2005-09-22 Thread George Sakkis
"Sen-Lung Chen" <[EMAIL PROTECTED]> wrote:
> Dear All:
>  I have a question of show percentage.
> For example ,I want to show the percentage of 1/3 = 33.33%
>
>  I use the 1*100/3 = 33
> it is 33 not 33.33 , how to show the 33.33 %
>  Thanks

"%.2f%%" % (100./3.)

Not quite the most readable expression in python.. ;)

George


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


Re: Newbie regular expression and whitespace question

2005-09-22 Thread George Sakkis
"googleboy" <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I am trying to collapse an html table into a single line.  Basically,
> anytime I see ">" & "<" with nothing but whitespace between them,  I'd
> like to remove all the whitespace, including newlines. I've read the
> how-to and I have tried a bunch of things,  but nothing seems to work
> for me:
>
> [snip]

As others have shown you already, you need to use the sub method of the re 
module:

import re
regex = re.compile(r'>\s*<')
print regex.sub('><',data)

> For extra kudos (and I confess I have been so stuck on the above
> problem I haven't put much thought into how to do this one) I'd like to
> be able to measure the number of characters between the  & 
> tags, and then insert a newline character at the end of the next word
> after an arbitrary number of characters.   I am reading in to a
> script a bunch of paragraphs formatted for a webpage, but they're all
> on one big long line and I would like to split them for readability.

What I guess you want to do is wrap some text. Do not reinvent the wheel, 
there's already a module
for that:

import textwrap
print textwrap.fill(oneBigLongLine, 60)

HTH,
George


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


Re: Using distutils 2.4 for python 2.3

2005-09-23 Thread George Sakkis
"Noam Raphael" <[EMAIL PROTECTED]> wrote:

> Hello,
>
> I want to distribute a package. It's compatible with Python 2.3.
> Is there a way to use distutils 2.4 feature package_data, while
> maintaining the distribution compatible with python 2.3 ?
>
> Thanks,
> Noam Raphael

You could distribute the whole 2.4 distutils package in yours so that setup.py 
finds it before the
default one. If distutils 2.4 is compatible with 2.3, that should work.

George


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


Re: Most direct way to strip unoprintable characters out of a string?

2005-09-24 Thread George Sakkis
"Steve Bergman" <[EMAIL PROTECTED]> wrote:

> When sanitizing data coming in from HTML forms, I'm doing this (lifted
> from the Python Cookbook):
>
> from string import maketrans, translate, printable
> allchars = maketrans('','')
> delchars = translate(allchars, allchars, printable)
> input_string = translate(input_string, allchars, delchars)
>
> Which is OK.  But it seems like there should be more straightforward way
> that I just haven't figured out.  Is there?

If by straightforward you mean one-liner, there is:
''.join(c for c in input_string if c not in string.printable)

If you care about performance though, string.translate is faster; as always, 
the best way to decide
on a performance issue is to profile the alternatives on your data and see if 
it's worth going for
the fastest one at the expense of readability.

George


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


Re: Parsing an HTML a tag

2005-09-24 Thread George Sakkis
"Stephen Prinster" <[EMAIL PROTECTED]> wrote:
> George wrote:
> > How can I parse an HTML file and collect only that the A tags. I have a
> > start for the code but an unable to figure out how to finish the code.
> > HTML_parse gets the data from the URL document. Thanks for the help
>
> Have you tried using Beautiful Soup?
>
> http://www.crummy.com/software/BeautifulSoup/

I agree; you can do what you want in two lines:

from BeautifulSoup import BeautifulSoup
hrefs = [link['href'] for link in BeautifulSoup(urllib.urlopen(url)).fetch('a')]

George


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


Re: Parsing an HTML a tag

2005-09-24 Thread George Sakkis

"George" <[EMAIL PROTECTED]> wrote:

> I'm very new to python and I have tried to read the tutorials but I am
> unable to understand exactly how I must do this problem.
>
> Specifically, the showIPnums function takes a URL as input, calls the
> read_page(url) function to obtain the entire page for that URL, and
> then lists, in sorted order, the IP addresses implied in the " HREF=· · ·>" tags within that page.
>
>
> """
> Module to print IP addresses of tags in web file containing HTML
>
> >>> showIPnums('http://22c118.cs.uiowa.edu/uploads/easy.html')
> ['0.0.0.0', '128.255.44.134', '128.255.45.54']
>
> >>> showIPnums('http://22c118.cs.uiowa.edu/uploads/pytorg.html')
> ['0.0.0.0', '128.255.135.49', '128.255.244.57', '128.255.30.11',
> '128.255.34.132', '128.255.44.51', '128.255.45.53',
> '128.255.45.54', '129.255.241.42', '64.202.167.129']
>
> """
>
> def read_page(url):
>  import formatter
>  import htmllib
>  import urllib
>
>  htmlp = htmllib.HTMLParser(formatter.NullFormatter())
>  htmlp.feed(urllib.urlopen(url).read())
>  htmlp.close()
>
> def showIPnums(URL):
>  page=read_page(URL)
>
> if __name__ == '__main__':
>  import doctest, sys
>  doctest.testmod(sys.modules[__name__])


You forgot to mention that you don't want duplicates in the result. Here's a 
function that passes
the doctest:

from urllib import urlopen
from urlparse import urlsplit
from socket import gethostbyname
from BeautifulSoup import BeautifulSoup

def showIPnums(url):
"""Return the unique IPs found in the anchors of the webpage at the given
url.

>>> showIPnums('http://22c118.cs.uiowa.edu/uploads/easy.html')
['0.0.0.0', '128.255.44.134', '128.255.45.54']
>>> showIPnums('http://22c118.cs.uiowa.edu/uploads/pytorg.html')
['0.0.0.0', '128.255.135.49', '128.255.244.57', '128.255.30.11', 
'128.255.34.132',
'128.255.44.51', '128.255.45.53', '128.255.45.54', '129.255.241.42', 
'64.202.167.129']
"""
hrefs = set()
for link in BeautifulSoup(urlopen(url)).fetch('a'):
try: hrefs.add(gethostbyname(urlsplit(link["href"])[1]))
except: pass
return sorted(hrefs)


HTH,
George


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

Re: Most direct way to strip unoprintable characters out of a string?

2005-09-25 Thread George Sakkis
"Steve Bergman" <[EMAIL PROTECTED]> wrote:

> George Sakkis wrote:
>
> >
> >
> >If by straightforward you mean one-liner, there is:
> >''.join(c for c in input_string if c not in string.printable)
> >
> >If you care about performance though, string.translate is faster; as always, 
> >the best way to
decide
> >on a performance issue is to profile the alternatives on your data and see 
> >if it's worth going
for
> >the fastest one at the expense of readability.
> >
> >
> >
> Thank you for the reply.  I was really thinking of some function in the
> standard library like:
>
> s = stripUnprintable(s)
>
> When I learned php, I more or less took the route of using whatever I
> found that 'worked'.  In learning Python, I'm trying to take my time and
> learn the 'right' (that's pronounced 'beautiful') way of doing things.
>
> As it stands, I've stashed the string.translate code in a short function
> with a comment explaining what it does and how.  I mainly didn't want to
> use that if there was some trivial built-in that everyone else uses.

No there's not a stripUnprintable in a standard module AFAIK, and that's a good 
thing; if every
little function that one might ever wanted made it to the standard library, the 
language would be
overwhelming.

Make sure you calculate the unprintable characters only the first time it is 
called, not every time.
Here's a way to encapsulate this in the same function, without polluting the 
global namespace with
allchars and delchars:

import string

def stripUnprintable(input_string):
try: filterUnprintable = stripUnprintable.filter
except AttributeError: # only the first time it is called
allchars = string.maketrans('','')
delchars = allchars.translate(allchars, string.printable)
filterUnprintable = stripUnprintable.filter = lambda input: 
input.translate(allchars,
delchars)
return filterUnprintable(input_string)

George


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


Re: unittest setup

2005-09-25 Thread George Sakkis
"paul kölle" <[EMAIL PROTECTED]> wrote:
>
> [snipped]
>
> It seems to me my case is not that exotic, I thought it would be quite
> natural to write the boilerplate stuff in setUp() and build on that to
> step through the applications state with test* methods each building on
> top of each other. Is that the wrong approach? Are there other
> frameworks supporting such a style?

Yes, py.test: http://codespeak.net/py/current/doc/test.html.

George


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

Re: Struggling with basics

2005-09-25 Thread George Sakkis
"Jason" <[EMAIL PROTECTED]> wrote:

> What I'd like to know is do you think it would be better to sort the
> list in memory, or print it out sorted?  If the latter, then naturally
> I'd need to change the showScores section to show the list in a reverse
> order.  But, would sorting the list in memory be more effective?

The list *is* sorted; the thing is that it is in ascending order (from lowest 
to highest) but you
would rather have it in descending. There are (at least) two alternatives:

1. Keep the list as it is now in ascending order and print it in reverse. In 
python 2.4, this is as
elegant and efficient as it can, using the reversed() builtin function. Just 
replace in showScores
"for score,name in self.hiScores" with "for score,name in 
reversed(self.hiScores)". reversed()
returns an iterator over the sequence, not a new list, so the memory overhead 
is minimal.

2. Instead of storing (score,name) pairs, store (-score,name). When a list of 
the latter is in
ascending order, the former is in descending. In this case of course, you have 
to make sure that
showScores() and lastScore() return the actual (positive) score, not the stored 
(negative) one.

I would go for the first alternative but YMMV.

George


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


Re: Struggling with this concept please help

2005-09-25 Thread George Sakkis
"George" <[EMAIL PROTECTED]> wrote:

> Hello everyone I know many have helped but I cannot get this to work
> out correctly. I cannot use BeautifulSoup at all. I need to:
> [snipped]

What do you mean you cannot use BeautifulSoup ? You cannot download it, install 
it, import it, or
you are not allowed to use it because it's a homework ? If it's the latter, I 
doubt that you'll get
a solution spelled out for you in this group.

George


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


Re: PEP 350: Codetags

2005-09-26 Thread George Sakkis
"Paul Rubin" <http://[EMAIL PROTECTED]> wrote:

> I'm opposed to pretty much every proposal of this sort.  If you want
> to propose adding a feature to the language, add it in a way that the
> compiler can know about it and notice when it's not used correctly.
> Mere conventions that are not checked by the compiler are just more
> stuff for people to remember.  That doesn't say they're always useless
> but in general they should not be the subject of PEP's.

There are more than a dozen "informational PEPs" so far, or two dozens if you 
count the meta-PEPs as
well (http://www.python.org/peps/). This PEP states upfront that it is 
informational, so I don't see
the problem, unless are you suggesting a (meta-)PEP against informational PEPs 
in general :-)

George


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


Sparse matrices

2005-09-26 Thread George Sakkis
Is there any sparse matrix package compatible with Numeric/Numarray ? Ideally, 
the implementation of
a matrix (dense/sparse) should be transparent to the application. However the 
APIs of the only
packages I'm aware of -- the Sparse module in Scipy and PySparse --are both 
pretty incomplete
compared to (dense) numeric arrays. Any alternatives ?

George


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


Re: backreferences

2005-09-28 Thread George Sakkis

"Amy Dillavou" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Can someone help me with understanding how python uses backreferences?
> I need to remember the item that was last matched by the re engine but i
> cant seem to understand anything that I find on backreferences.  if I
> want to access the last match do i use \number or is there something
> else i have to do?
>
> heres part of my code:
> renDate = re.compile("$((\d){4}-(\d){2}-(\d){2}))")
> renDate.search(l)
> if(exist.search(l) and str(lastmodDate) < \1): #i need help here with \1
>
> Thanks in advance
> A.D

renDate = re.compile(some_regex)
match = renDate.search(input)
if match and str(lastmodDate) < match.group(1):
do_something()


HTH,
George


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


Re: grouping array

2005-09-29 Thread George Sakkis
<[EMAIL PROTECTED]> wrote:

> hi if I have an array
>
> say x = [[2,2,0,0,1,1],
>  [1,1,0,0,1,1],
>  [1,1,0,0,1,1]]
> I basically want to group regions that are non zero like I want to get
> the coordinates of non zero regions..as (x1,y1,x2,y2)
> [(0,0,2,1),(0,4,2,5)] which show the top left(x1,y1) and bottom
> right(x2,y2) corners of each group.hope i am clear.
>
> Thanks

I guess you imply rectangular regions only ? If not, what's the output supposed 
to be for

[[2,2,0,0,1,1],
 [1,1,3,0,0,1],
 [1,1,3,0,1,1]]

or

[[2,2,2,2],
 [1,0,3,3],
 [1,1,3,0]]

George


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


Re: Opinion on Pyrex

2005-09-30 Thread George Sakkis
"Carl" <[EMAIL PROTECTED]> wrote:

> I have recently started to use Pyrex and am amazed by it's useability.
>
> Are there any alternatives to Pyrex?
>
> One thing that I haven't figured out is how to embed pure C/C++ source code
> into Pyrex. For example, if you have a bunch of C files that you want to
> use together with some Python code snippets, how do you practically achieve
> this using Pyrex? I have come to the conclusion that it is not possible
> without some rewriting and adaptation (translation) of available C source
> code (if you don't want to compile and link all your C source into a
> statical or dynamical library).
>
> Carl

You may want to check out weave: http://www.scipy.org/documentation/weave/

George


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


Re: "no variable or argument declarations are necessary."

2005-10-02 Thread George Sakkis
"Michael" <[EMAIL PROTECTED]> wrote:

> James A. Donald wrote:
> > On Sun, 02 Oct 2005 17:11:13 -0400, Jean-Francois Doyon
> > James A. Donald:
> >>  > Surely that means that if I misspell a variable name, my program will
> >>  > mysteriously fail to work with no error message.
> >> No, the error message will be pretty clear actually :)
> > Now why, I wonder,  does this loop never end :-)
> > egold = 0
> > while egold < 10:
> >ego1d = egold+1
>
> I know (hope! :-) that's a tongue-in-cheek question, however the answer as
> to why that's not a problem is more to do with development habits rather
> than language enforcement. (yes with bad habits that can and will happen)
>
> [snipped description of test-driven development culture]

As an aside, more to the point of the specific erroneous example is the lack of 
the standard python
idiom for iteration:

for egold in xrange(10):
pass

Learning and using standard idioms is an essential part of learning a language; 
python is no
exception to this.

George


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


Re: "no variable or argument declarations are necessary."

2005-10-03 Thread George Sakkis
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote

> [snipped]
> No compiler will catch this error:
>
> x = 12.0 # feet
> # three pages of code
> y = 15.0 # metres
> # three more pages of code
> distance = x + y
> if distance < 27:
> fire_retro_rockets()

Actually modern compilers can 
(http://www.boost.org/libs/mpl/doc/tutorial/dimensional-analysis.html)
at the expense of the programmer's eye health...

George


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


Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-07 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote:

> Ok, that one looks more sleak than what I came up with.

For the most efficient and elegant solution, check out Raymond Hettinger's 
reply to:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/141934

George


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

Re: Python recipes: list mixin, improved timeit, etc

2005-10-07 Thread George Sakkis
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote:

> I've just found this:
>
> [quote]
> A mixin class is a parent class that is inherited from - but not as
> a means of specialization. Typically, the mixin will export services to a
> child class, but no semantics will be implied about the child "being a
> kind of" the parent.
> [end quote]
>
> from http://c2.com/cgi/wiki?MixIn
>
> Is that all they are?
>
> It is amazing how you can take the simplest concept, and by using
> appropriate terminology, make it as confusing and opaque as you want...
>
> *wink*

 Now this reminds me of Xah's entertaining posts about "moronicities of the 
tech-geek industry
jargon" .

George


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


Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-07 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote:

> Thanks, that looks like Mike's solution except that it uses the
> built-in heapq module.

This make a big difference for the algorithmic complexity; replacing an item in 
a heap is much more
efficient than sorting the whole list.

> While this one contains less code than Mike's solution it seems to lack
> the ability to control the comparison operation, which means it won't
> work in my case. I need to both be able to sort on an arbitrary field
> name (could be done using a list where I place the field first), and
> also to be able to sort in a different order than smallest-first.
>
> Perhaps by adjusting the data that is returned through each source
> would do that. I'll look into it.

Yes, it's a little inconvenient that the builtin heap doesn't take a comparison 
operation but you
can easily roll your own heap by transforming each item to a (key,item) tuple. 
Now that I'm thinking
about it, it might be a good addition to the cookbook.

George


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

Re: Objects with different data views

2005-10-07 Thread George Sakkis
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote:

> I'm not sure how to do this, or where to start looking for the right
> information, so any advice would be appreciated.
>
> I want to implement a class with two (or more) different ways of looking
> at its attributes.
>
> One example of this might be complex numbers, which can be written in
> Cartesian form (x+yi) or polar form (r cis theta).
>
> (Yes, I know Python already has complex numbers. That was just an example.)
>
> Another might be 3D vectors, which can be written in Cartesian form
> [x, y, z], polar form [r, theta, z] or spherical polar [r, theta, phi].
>
> It is important that there are no privileged attributes, e.g. in the
> above example, I can set any of x, y, z, r, theta or phi and all the
> others will automatically reflect the changes. A concrete, if simple,
> example will make it clear.
>
> Suppose I have a transformation (a,b) <-> (x,y) where:
>
> x = a+b
> y = a+2*b
>
> I create an instance spam, and set a and b:
>
> spam.a = 1
> spam.b = 2
>
> Now I should be able to read x and y:
>
> print spam.x, spam.y
> # prints 3 5
>
> If I set attribute y:
>
> spam.y = 0
>
> a and b automatically change to match:
>
> print spam.a, spam.b
> # prints 6, -3
>
>
> Anyone have any good ideas for how I should implement this?

As others have replied, properties is the way to go. There have been a few 
recipes in the Cookbook
that avoid cluttering the class namespace with temporary get/set/del methods, 
e.g.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698.

HTH,
George


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


Re: Best way to share a python list of objects

2005-10-07 Thread George Sakkis
"kyle.tk" <[EMAIL PROTECTED]> wrote:

> So I have a central list of python objects that I want to be able to
> share between different process that are possibly on different
> computers on the network. Some of the processes will add objects to
> list and another process will be a GUI that will view objects in the
> list. I want this all to happen in real-time (e.g once a processes adds
> an object to the list the GUI will see it.)
>
> What would be the best way to accomplish this. Some of my ideas:
> - An XML file r/w-able by all processes
> - Send pickled objects between all processes and each keeps it own list
> locally
> - A ascii type protocol akin to ftp the hands out all the info to the
> processes
>
> Any other ideas? What would work the best

If all the processes are python, I would check Pyro first: 
http://pyro.sourceforge.net/.

George


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


Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-08 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > George Sakkis <[EMAIL PROTECTED]> wrote:
> 
> >>Yes, it's a little inconvenient that the builtin heap doesn't take a
> >>comparison operation but you can easily roll your own heap by transforming
> >>each item to a (key,item) tuple. Now that I'm thinking about it, it might
> >>be a good addition to the cookbook.
> >
> >
> > I believe Python 2.5 adds a key= argument to heapq's functions...
> 
>
> I will revisit the heapq solution when 2.5 is released then.
>
> Thanks for the heads up. For the moment I will stay with the list
> solution that Mike came up with slightly changed to accomodate tips and
> pointers from others in this thread.

Just added a recipe at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440673. You can try
both and see if there's any significant performance difference for your data.

George


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

Re: Function decorator that caches function results

2005-10-08 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote:

> [snip]
>
> Ok, so I thought, how about creating a decorator that caches the
> function results and retrieves them from cache if possible, otherwise it
> calls the function and store the value in the cache for the next invokation.
>
> [snip]

Cool, you re-invented the memoization pattern:
http://en.wikipedia.org/wiki/Memoization
http://aspn.activestate.com/ASPN/search?query=memoize&x=0&y=0§ion=PYTHONCKBK&type=Subsection

Yes, it's kinda discouraging that most interesting ideas have already been 
conceived, implemented
and used by others...

George


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

Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-08 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote:

> George Sakkis wrote:
> 
> > Just added a recipe at 
> > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440673. You can
try
> > both and see if there's any significant performance difference for your 
> > data.
> 
>
> Thanks, will take a look at it later. The sort solution seems to work
> nicely. Might be a big difference if I have a lot of sources though as I
> bet the overhead in doing a sort of N items gets higher than doing a
> manipulation of a heap to place an item in the right spot, but with 4-5
> or a few more sources might not make an impact at all.

Unless you're talking about hundreds or thousands sources, it probably
won't. I would still go for the heap solution since IMO the resulting
code it's more readable and easier to understand.

George

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


Re: how do you pronounce wxpython

2005-10-08 Thread George Sakkis
"Alex" <[EMAIL PROTECTED]> wrote:

> My native language is not English so I just wonder how you pronounce
> wxPython.
>
> vi-ex python
> double-you-ex python
> wax-python
>
> or something else
>
> Thanks

I am sure it is pronounced the same way as wxWidgets .

George


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


Re: Python reliability

2005-10-09 Thread George Sakkis
Steven D'Aprano wrote:

> On Sun, 09 Oct 2005 23:00:04 +0300, Ville Voipio wrote:
>
> > I would need to make some high-reliability software
> > running on Linux in an embedded system. Performance
> > (or lack of it) is not an issue, reliability is.
>
> [snip]
>
> > The software should be running continously for
> > practically forever (at least a year without a reboot).
> > Is the Python interpreter (on Linux) stable and
> > leak-free enough to achieve this?
>
> If performance is really not such an issue, would it really matter if you
> periodically restarted Python? Starting Python takes a tiny amount of time:

You must have missed or misinterpreted the "The software should be
running continously for practically forever" part. The problem of
restarting python is not the 200 msec lost but putting at stake
reliability (e.g. for health monitoring devices, avionics, nuclear
reactor controllers, etc.) and robustness (e.g. a computation that
takes weeks of cpu time to complete is interrupted without the
possibility to restart from the point it stopped).

George

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


Re: Newbie Count Question

2005-10-09 Thread George Sakkis
"ProvoWallis" wrote:

> I've managed to get this far thanks to looking at other
> posts on the board but no matter waht I try all of the
> sections end up being numbered for the total number of
> sections in the document. e.g., if there are 100 sections
> in the document the "no" attribute is "1.100"
> for each one.

Of course it is; the counter you compute is fixed and equal to
len(all). What you need is a substitution function that keeps track of
the counter and increments it by one for every substitution. This means
that the counter becomes part of the function's state. When you hear
"function" and "state" together, the typical solution is "class":

import re

class ReplaceSecMain(object):
def __init__(self):
self._count = 0
self._secmain_re = re.compile(r'''
(?<=  ) # positive lookahead assertion
''', re.IGNORECASE | re.VERBOSE)

def sub(self, text):
return self._secmain_re.sub(self._subNum, text)

def _subNum(self, match):
self._count += 1
return '%s.%.2d' % (match.group(1), self._count)


print ReplaceSecMain().sub(open("myfile.txt").read())


I also cleaned up the regular expression a little; google for
lookahead/lookbehind assertions if you haven't seen them before.

HTH,
George

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


Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-10 Thread George Sakkis
"Alex Martelli" <[EMAIL PROTECTED]> wrote:

> George Sakkis <[EMAIL PROTECTED]> wrote:
>...
> > > manipulation of a heap to place an item in the right spot, but with 4-5
> > > or a few more sources might not make an impact at all.
> >
> > Unless you're talking about hundreds or thousands sources, it probably
> > won't. I would still go for the heap solution since IMO the resulting
> > code it's more readable and easier to understand.
>
> I'm not so sure about either sentence...:
>
> Helen:~/pynut/samp alex$ python merger.py --numstreams=10 --minlen=100
> --how=S
> Best time for 10 loops: 0.247116088867
>
> Helen:~/pynut/samp alex$ python merger.py --numstreams=10 --minlen=100
> --how=H
> Best time for 10 loops: 0.10344004631
>
> i.e., a heap solution may be over 4 times faster than a sort-based one
> (in the following implementations).

Interesting; I thought timsort on small almost ordered lists would be 
practically as fast as the
heap. Still, how is 0.10344 over 4 times faster than 0.247116 ?

> Readability seems quite comparable
> (skipping the rest of the infrastructure, which generates random sorted
> streams and ensures a stream is exhausted and verifies it etc etc):
>
> def merge_by_sort(streams):
>   sources = [[s.next(), i, s.next] for i, s in enumerate(streams)]
>   while sources:
> sources.sort(reverse=True)
> best_source = sources[-1]
> yield best_source[0]
> try: best_source[0] = best_source[-1]()
> except StopIteration: sources.pop()
>
> def merge_by_heap(streams):
>   sources = [[s.next(), i, s.next] for i, s in enumerate(streams)]
>   heapq.heapify(sources)
>   while sources:
> best_source = sources[0]
> yield best_source[0]
> try: best_source[0] = best_source[-1]()
> except StopIteration: heapq.heappop(sources)
> else: heapq.heapreplace(sources, best_source)

Indeed, these are almost equivalent as far as readability goes; the previous 
examples in the thread
were less clear. By the way, why do you need 'i' and enumerate above ?

> Hmmm, I wonder if something like merge_by_heap would be a good candidate
> for itertool.  Raymond...?
>
>
> Alex

Yes, it would be nice to make it into 2.5.

George


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


Re: best Pythonic way to do this sort: Python newb

2005-10-10 Thread George Sakkis
"Satchidanand Haridas" <[EMAIL PROTECTED]> wrote:

> >So, I want to sort myList by the return of myFunction( value3 )
> >
> >I tried doing the following... with no luck so far
> >myList.sort(lambda x, y: cmp(myFunction(x[2]), myFunction(y[2]))
> >
> >
> >
> I think the above statement should be as follows:
>
> myList.sort(lambda x, y: cmp(myFunction(x[2]) - myFunction(y[2]))
>
>
>
> hope that helps.

It would help more if you tested it before you posted. cmp takes two arguments 
(let alone that
subtraction may not be defined for the list elements), so the original version 
is correct.

George


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


Re: Comparing lists

2005-10-10 Thread George Sakkis
"Christian Stapfer" <[EMAIL PROTECTED]> wrote:

> <[EMAIL PROTECTED]> wrote:
> > try to use set.
>
> Sorting the two lists and then extracting
> A-B, B-A, A|B, A & B and A ^ B in one single
> pass seems to me very likely to be much faster
> for large lists.

Why don't you implement it, test it and time it to be more convincing about 
your intuition ?

George


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


set.__getstate__ not overriden

2005-10-10 Thread George Sakkis
>>> import pickle
>>> class Foo(set):
... def __getstate__(self): assert False

>>> pickle.dumps(Foo())
# doesn't raise AssertionError

The same happens with frozenset. Before I submit it to the bugs
tracker, is there a chance this is a 'feature' ?

George

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


Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-10 Thread George Sakkis
"Dave Hansen" <[EMAIL PROTECTED]> wrote:

> On Mon, 10 Oct 2005 16:42:34 -0500, Terry Hancock
> <[EMAIL PROTECTED]> wrote:
>
> >On Sunday 09 October 2005 07:50 am, phil hunt wrote:
> >> On Fri, 7 Oct 2005 01:05:12 -0500, Terry Hancock <[EMAIL PROTECTED]> wrote:
> >> >GvR's syntax has the advantage of making grammatical sense in English 
> >> >(i.e.
> >> >reading it as written pretty much makes sense).
> >>
> >> I know, let's re-write Python to make it more like COBOL! That's
> >> bound to be a winner!
> >
> >Whereas the "natural order" of "condition affirmative negative" is natural
> >for what reason?  That it is so in C?
>
> And Basic, and Fortran, and Lisp, and just about any programming
> language you care to name, including python (if Condition: Affirmative
> else: Negative).

Block delimiters (curly braces, if/fi, begin/end, etc.) are also in just about 
any language but this
didn't stop python using indentation instead, so what's your point ? Conformity 
and backwards
compatibility should not be top priorities in language design; fortunately for 
python, they're not.

George


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


Re: How to do *args, **kwargs properly

2005-10-11 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote:

> So what you're saying is that instead of:
>
> def fn(*values, **options):
>
> I should use:
>
> def fn(values, cmp=cmp):
>
> in this specific case?
>
> and then instead of:
>
> fn(1, 2, 3, cmp=...)
>
> this:
>
> fn([1, 2, 3], cmp=...)
>
> 
>
> I think I'll re-write to use a list instead

Actually in most cases you don't need to assume it's a list; any
iterable is usually good enough. You can always turn it into a list (or
a tuple or a set or..) in the function if you really have to. So when
you do have to and when you don't ? You don't have to if all you do is
iterate over the elements. This is true even if you want to iterate
more than once; just use the itertools.tee() function to create N
independent iterators. To sum up, a better signature for your function
is likely to be "def fn(iterable, cmp=cmp)".

George

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


Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-11 Thread George Sakkis
> Function name is perhaps not the best one. It occurs to me that this
> is the GROUP BY in SQL so perhaps a different name is better, but
> then again this might be moot if such a already exists somewhere :)

Amazing, you keep reinventing things, even with the exact same name :)

from itertools import imap,groupby
from operator import itemgetter

for fruit,group in groupby(fruits, itemgetter(0)):
print fruit, "has a sum of", sum(imap(itemgetter(1),group))

For this to work as intended, fruits has to be already sorted by the
same key given to grouby; otherwise just replace fruits with
sorted(fruits, itemgetter(0)).

By the way, read all the functions in the itertools module
(http://docs.python.org/lib/itertools-functions.html), it will save you
a lot of time.

George

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


Re: A Tree class, my $0.02 contribution to the python community.

2005-10-12 Thread George Sakkis
"Antoon Pardon" <[EMAIL PROTECTED]> wrote:
> Comments are welcome:
>
>   http://www.pardon-sleeuwaegen.be/antoon/avltree.html

How about adding two shortcut methods, nextkey(k) and prevkey(k), to return the 
next and previous
key respectively ? For instance nextkey would be equivalent to (untested):

def nextkey(self, key):
iter = self[key:]
first = iter.next()
if key not in self: return first
else: return iter.next()

Also for consistency, nextvalue(k), prevvalue(k), nextitem(k), previtem(k) 
would be reasonable
additions.

And a question: what does step do if the keys are not integers since you 
restrict step to be integer
?

George


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


Re: Multiple assignments simplification

2005-10-12 Thread George Sakkis
<[EMAIL PROTECTED]> wrote:

> [snipped]
>
> Do you know some algorithm (or you can give some suggestions) to
> minimize the number of simple assignments needed for a "regular"
> situation like that?

You can formulate the task as a graph-theoretic problem by representing the set 
of assignments as a
digraph G(V,E), where:
- V = set(LHS) | set(RHS): the vertex set V is the union of all left and right 
hand side
expressions.
- E = set((v1,v2) for "v1 = v2" in assignments): there is an edge from v1 to v2 
for every assignment
v1=v2.

Now, every edge v1->v2 where in-degree(v1)==0 corresponds to a safe assignment: 
v1 is not assigned
to any RHS, so it can be overwritten. After the assignment, both v1 and the 
edge (v1,v2) can be
removed, decrementing the in-degree of v2. This happens iteratively as long as 
there are nodes with
zero in-degree.

At this point, all remaining nodes have in-degree >=1 and they form one or more 
strongly connected
components. Since no RHS occurs more than once*, the out-degree of every vertex 
is less than or
equal to 1. Therefore, for every component Ci,
|Vi| >= sum(out-degree(v) for v in Vi)  == |Ei|.

Since for a strongly connected component |Vi| <= |Ei|, the previous 
relationship is actually
equality |Vi| == |Ei|. Thus each component is a simple cycle 
v[1]->v[2]->...v[n]->v[1]. You can
break the cycle by introducing an auxiliary variable x in an arbitrary edge, 
say v[n]->v[1]. Then
the following assignments can take place: x = v[1]; v[1] = v[2]; v[2] = v[3]; 
...; v[n-1] = v[n];
v[n] = x

So overall, you need just one auxiliary variable for each strongly component of 
G.

HTH,
George


* More than one assignments with the same RHS [v=a, v=b] are useless since only 
the last has an
effect. In any case, the useless assignments can be filtered out in the 
beginning.


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


  1   2   3   4   5   6   7   8   9   10   >