Call for papers: SETP-10, USA, July 2010

2010-05-18 Thread James Heralds
It would be highly appreciated if you could share this announcement
with your colleagues, students and individuals whose research is in
software engineering, software testing, software quality assurance,
software design and related areas.

Call for papers: SETP-10, USA, July 2010

The 2010 International Conference on Software Engineering Theory and
Practice (SETP-10) (website: http://www.PromoteResearch.org ) will be
held during 12-14 of July 2010 in Orlando, FL, USA.  SETP is an
important event in the areas of Software development, maintenance, and
other areas of software engineering and related topics.

The conference will be held at the same time and location where
several other major international conferences will be taking place.
The conference will be held as part of 2010 multi-conference
(MULTICONF-10). MULTICONF-10 will be held during July 12-14, 2010 in
Orlando, Florida, USA. The primary goal of MULTICONF is to promote
research and developmental activities in computer science, information
technology, control engineering, and related fields. Another goal is
to promote the dissemination of research to a multidisciplinary
audience and to facilitate communication among researchers,
developers, practitioners in different fields. The following
conferences are planned to be organized as part of MULTICONF-10.

•   International Conference on Artificial Intelligence and Pattern
Recognition (AIPR-10)
•International Conference on Automation, Robotics and Control
Systems (ARCS-10)
•   International Conference on Bioinformatics, Computational Biology,
Genomics and Chemoinformatics (BCBGC-10)
•   International Conference on Computer Communications and Networks
(CCN-10)
•   International Conference on Enterprise Information Systems and Web
Technologies (EISWT-10)
•   International Conference on High Performance Computing Systems
(HPCS-10)
•   International Conference on Information Security and Privacy
(ISP-10)
•   International Conference on Image and Video Processing and Computer
Vision (IVPCV-10)
•   International Conference on Software Engineering Theory and Practice
(SETP-10)
•   International Conference on Theoretical and Mathematical Foundations
of Computer Science (TMFCS-10)

MULTICONF-10 will be held at Imperial Swan Hotel and Suites.  It is a
full-service resort that puts you in the middle of the fun! Located
1/2 block south of the famed International Drive, the hotel is just
minutes from great entertainment like Walt Disney World® Resort,
Universal Studios and Sea World Orlando. Guests can enjoy free
scheduled transportation to these theme parks, as well as spacious
accommodations, outdoor pools and on-site dining — all situated on 10
tropically landscaped acres. Here, guests can experience a full-
service resort with discount hotel pricing in Orlando.


We invite draft paper submissions. Please see the website
http://www.PromoteResearch.org  for more details.

Sincerely
James Heralds
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: getting attributes and methods of class without creating object

2010-05-18 Thread shuvro
On May 18, 11:50 am, Patrick Maupin pmau...@gmail.com wrote:
 On May 17, 10:52 pm, shuvro shuvr...@gmail.com wrote:



  Suppose I have a class like this -

  class myClass(object):

      def __init__(self):
          self.a = 10
          self.b = 20

      def my_method(self,var = 20):
          self.local_var = var

  I want to know about its method(__init__ and my_method) and
  variables(a,b, local_var) without creating the object of it. I tried
  getmembers function of inspect module. But it can do this with an
  object of myClass as argument. Like

  import inspect
  var = myClass()
  inspect.getmembers(var)

  I have to know about this without creating the object of myClass.
  Can anyone help me please?

 Well, you can do the same thing with myClass itself:

 inspect.getmembers(myClass)

 But that won't show you a,b, or local_var, because those don't belong
 to the class.  They only belong to class instances, and maybe even not
 all class instances.  (For example, if my_method is not called, then
 the instance won't have local_var defined.)

 Python is a very dynamic language, and class instances (and even the
 classes themselves!) can be modified at any time during execution.
 You don't even have to be executing inside a class's function to add
 stuff to it:

 class foo:
     pass

 bar = foo()
 bar.a = 3

 So to know about the attributes of an instance of a class without
 actually creating that instance is very difficult.  You didn't specify
 why you want to do this, but often the reason is to try to catch
 potential errors without actually running code.  This is typically
 called linting, and there are a few Python packages designed to do
 this, such as pylint and pychecker.  Probably others, but I don't know
 anything about them, because I find that in most cases, the best way
 to test or to reason about Python code is to actually run it.

 Regards,
 Pat

Thanks Pat for your informative reply.
Actually what I am trying to do is to write an external exporter for
the data types an open source software(Blender). So, I have to collect
the properties of the classes.
Here, I have no chance to edit the class and add inspect codes there,
neither I can create objects of the
existing classes (that will do some additional things which I not
want).
Is it not possible with the existing python facilities (without adding
external libraries) ?


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


Re: url fetching from xml depending upon selection

2010-05-18 Thread Stefan Behnel

shanti bhushan, 18.05.2010 07:18:

I have a sample.XML file
the code is like this

?xml version=1.0 encoding=UTF-8?
opml version=1.0
head
titleMy Podcasts/title
dateCreatedSun, 07 Mar 2010 15:53:26

GMT/dateCreated
dateModifiedSun, 07 Mar 2010 15:53:26

GMT/dateModified
/head
body
   TestCase name=Sprint_001
 Input url=http://first.co.jp; /
 Input url=http://www.google.com; /
 Input url=http://www.epaper.times.india.com; /
   /TestCase
   TestCase name=Sprint_002
 Input url=http://second.co.jp; /
 Input url=http://www.google.com; /
 Input url=http://www.epaper.times.india.com; /
   /TestCase
   TestCase name=Sprint_003
 Input url=http://third.co.jp; /
 Input url=http://www.google.com; /
 Input url=http://www.epaper.times.india.com; /
   /TestCase
/body
/opml


This my python code
from xml.etree import ElementTree

with open('our.xml', 'rt') as f:
 tree = ElementTree.parse(f)

for node, value in tree.findall('.//TestCase/Input'):

 url=node.attrib.get('url')
 print url

i want to print the url depending on name=sprint_001.


for test_case in tree.findall('.//TestCase'):
if test_case.get('name') == 'sprint_002':
   for input_el in test_case:
   print input_el.get('url')

Stefan

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


Re: pickle unable to load collection

2010-05-18 Thread Peter Otten
paragk wrote:

 Hi,
 
 I am unable to figure out the cause of python pickle unable to find
 the collection module.
 
 I am getting
 
 __import__(module)
 ImportError: No module named collections
 
 when I try to load a pickled object.
 
 Details:
 
 Python version:
 
 Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit
 (Intel)] on win32
 
 
 [CODE]
 
 import sys
 import glob
 import collections
 import pickle
 
 ...
 
 SomeListDict = collections.defaultdict(list)
 
 ... # Populate SomeListDict
 
 DictFile = open (options.saveDict, 'w')
 pickle.dump(SomeListDict , DictFile, -1)
 DictFile.close()

[...]

 From the above analysis, clearly the collection module exists, since
 the dump works.
 
 What am I missing?

You have to open the file in binary mode wb.

 import collections
 import pickle
 data = pickle.dumps(collections.defaultdict())
 pickle.loads(data)
defaultdict(None, {})

Now simulate the effect of writing in text mode and reading in binary mode:

 garbled_data = data.replace(\n, \r\n)
 pickle.loads(garbled_data)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.6/pickle.py, line 1374, in loads
return Unpickler(file).load()
  File /usr/lib/python2.6/pickle.py, line 858, in load
dispatch[key](self)
  File /usr/lib/python2.6/pickle.py, line 1090, in load_global
klass = self.find_class(module, name)
  File /usr/lib/python2.6/pickle.py, line 1124, in find_class
__import__(module)
ImportError: No module named collections

 try: pickle.loads(garbled_data)
... except ImportError as e:
... e
...
ImportError('No module named collections\r',)

So as Steven suspected there was a whitespace char in the module name: 
pickle.load() was looking for the collections\r module.

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


Re: Pyserial and pysqlite data types, need advice

2010-05-18 Thread jon vs. python
The best thing I've found is this:

http://eli.thegreenplace.net/2009/05/29/storing-blobs-in-a-sqlite-db-with-pythonpysqlite/

On Mon, May 17, 2010 at 5:05 PM, jon vs. python jonvspyt...@gmail.comwrote:

 Hi,
 I'm trying to store frames received via serial port (using Pyserial) into a
 sqlite database (using Pysqlite) in order to perform off-line processing.
 Thus I could use both SQL's power and Python's magic to make everything
 easier. I'd like my code to be generic and work both for binary and ascii
 protocols, too.

 Which kind of data should I use to store the frames?
 Should I store every byte as a char in VARCHAR? (This seems to fail when
 trying to store non printable characters).
 Should I encapsulate frames in buffer objects and store them in BLOBs?
 (This seems to work but hides content and thus doesn't allow to use database
 operations directly on the data)
 I've also tried, unsuccessfully, to use bytearrays with pysqlite...

 Any suggestion?

 Thanks, Jon.

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


Re: url fetching from xml depending upon selection

2010-05-18 Thread shanti bhushan
On May 18, 10:18 am, shanti bhushan ershantibhus...@gmail.com wrote:
 I have a sample.XML file
 the code is like this

 ?xml version=1.0 encoding=UTF-8?
 opml version=1.0
 head
         titleMy Podcasts/title
         dateCreatedSun, 07 Mar 2010 15:53:26

 GMT/dateCreated
         dateModifiedSun, 07 Mar 2010 15:53:26

 GMT/dateModified
 /head
 body
   TestCase name=Sprint_001
     Input url=http://first.co.jp; /
     Input url=http://www.google.com; /
     Input url=http://www.epaper.times.india.com; /
   /TestCase
   TestCase name=Sprint_002
     Input url=http://second.co.jp; /
     Input url=http://www.google.com; /
     Input url=http://www.epaper.times.india.com; /
   /TestCase
   TestCase name=Sprint_003
     Input url=http://third.co.jp; /
     Input url=http://www.google.com; /
     Input url=http://www.epaper.times.india.com; /
   /TestCase
 /body
 /opml

 This my python code
 from xml.etree import ElementTree

 with open('our.xml', 'rt') as f:
     tree = ElementTree.parse(f)

 for node, value in tree.findall('.//TestCase/Input'):

         url=node.attrib.get('url')
         print url

 i want to print the url depending on name=sprint_001.
 If i change my option to sprint_002 it should print url for sprint_002


i have tried some new things here

from xml.etree import ElementTree

with open('our.xml', 'rt') as f:
tree = ElementTree.parse(f)

for node in tree.findall('.//TestCase/'):
print node.attrib.keys()
print node.attrib.items()
print node.attrib.get(1)

url=node.attrib.get('url')
print url



but i am not getting idea ... how to achive my motive
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: url fetching from xml depending upon selection

2010-05-18 Thread shanti bhushan
On May 18, 12:04 pm, Stefan Behnel stefan...@behnel.de wrote:
 shanti bhushan, 18.05.2010 07:18:





  I have a sample.XML file
  the code is like this

  ?xml version=1.0 encoding=UTF-8?
  opml version=1.0
  head
     titleMy Podcasts/title
     dateCreatedSun, 07 Mar 2010 15:53:26

  GMT/dateCreated
     dateModifiedSun, 07 Mar 2010 15:53:26

  GMT/dateModified
  /head
  body
     TestCase name=Sprint_001
       Input url=http://first.co.jp; /
       Input url=http://www.google.com; /
       Input url=http://www.epaper.times.india.com; /
     /TestCase
     TestCase name=Sprint_002
       Input url=http://second.co.jp; /
       Input url=http://www.google.com; /
       Input url=http://www.epaper.times.india.com; /
     /TestCase
     TestCase name=Sprint_003
       Input url=http://third.co.jp; /
       Input url=http://www.google.com; /
       Input url=http://www.epaper.times.india.com; /
     /TestCase
  /body
  /opml

  This my python code
  from xml.etree import ElementTree

  with open('our.xml', 'rt') as f:
       tree = ElementTree.parse(f)

  for node, value in tree.findall('.//TestCase/Input'):

           url=node.attrib.get('url')
           print url

  i want to print the url depending on name=sprint_001.

      for test_case in tree.findall('.//TestCase'):
          if test_case.get('name') == 'sprint_002':
             for input_el in test_case:
                 print input_el.get('url')

 Stefan- Hide quoted text -

 - Show quoted text -

Hi Stevan
i tried your logic i am not getting any out put for this
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: url fetching from xml depending upon selection

2010-05-18 Thread Stefan Behnel

shanti bhushan, 18.05.2010 07:18:

I have a sample.XML file
the code is like this

?xml version=1.0 encoding=UTF-8?
opml version=1.0
head
titleMy Podcasts/title
dateCreatedSun, 07 Mar 2010 15:53:26

GMT/dateCreated
dateModifiedSun, 07 Mar 2010 15:53:26

GMT/dateModified
/head
body
   TestCase name=Sprint_001
 Input url=http://first.co.jp; /
 Input url=http://www.google.com; /
 Input url=http://www.epaper.times.india.com; /
   /TestCase
   TestCase name=Sprint_002
 Input url=http://second.co.jp; /
 Input url=http://www.google.com; /
 Input url=http://www.epaper.times.india.com; /
   /TestCase
   TestCase name=Sprint_003
 Input url=http://third.co.jp; /
 Input url=http://www.google.com; /
 Input url=http://www.epaper.times.india.com; /
   /TestCase
/body
/opml


This my python code
from xml.etree import ElementTree

with open('our.xml', 'rt') as f:
 tree = ElementTree.parse(f)

for node, value in tree.findall('.//TestCase/Input'):

 url=node.attrib.get('url')
 print url



i want to print the url depending on name=sprint_001.
If i change my option to sprint_002 it should print url for sprint_002


Actually, try this:

test_cases = dict(
 (test_case.get('name'), [ el.get('url') for el in test_case ])
 for test_case in tree.findall('.//TestCase') )

print test_cases['Sprint_001']   # - prints list of URLs

That gives you a dict of test case names that are mapped to the list of 
their URLs.


Stefan

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


Re: url fetching from xml depending upon selection

2010-05-18 Thread shanti bhushan
On May 18, 12:04 pm, Stefan Behnel stefan...@behnel.de wrote:
 shanti bhushan, 18.05.2010 07:18:





  I have a sample.XML file
  the code is like this

  ?xml version=1.0 encoding=UTF-8?
  opml version=1.0
  head
     titleMy Podcasts/title
     dateCreatedSun, 07 Mar 2010 15:53:26

  GMT/dateCreated
     dateModifiedSun, 07 Mar 2010 15:53:26

  GMT/dateModified
  /head
  body
     TestCase name=Sprint_001
       Input url=http://first.co.jp; /
       Input url=http://www.google.com; /
       Input url=http://www.epaper.times.india.com; /
     /TestCase
     TestCase name=Sprint_002
       Input url=http://second.co.jp; /
       Input url=http://www.google.com; /
       Input url=http://www.epaper.times.india.com; /
     /TestCase
     TestCase name=Sprint_003
       Input url=http://third.co.jp; /
       Input url=http://www.google.com; /
       Input url=http://www.epaper.times.india.com; /
     /TestCase
  /body
  /opml

  This my python code
  from xml.etree import ElementTree

  with open('our.xml', 'rt') as f:
       tree = ElementTree.parse(f)

  for node, value in tree.findall('.//TestCase/Input'):

           url=node.attrib.get('url')
           print url

  i want to print the url depending on name=sprint_001.

      for test_case in tree.findall('.//TestCase'):
          if test_case.get('name') == 'sprint_002':
             for input_el in test_case:
                 print input_el.get('url')

 Stefan- Hide quoted text -

 - Show quoted text -

Great Help Stefan -
my regards to you
thankyou once again it waorks fine ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: url fetching from xml depending upon selection

2010-05-18 Thread Stefan Behnel

shanti bhushan, 18.05.2010 10:08:

On May 18, 12:04 pm, Stefan Behnelstefan...@behnel.de  wrote:

shanti bhushan, 18.05.2010 07:18:

 [...]

body
TestCase name=Sprint_001
  Input url=http://first.co.jp; /
  Input url=http://www.google.com; /
  Input url=http://www.epaper.times.india.com; /
/TestCase
TestCase name=Sprint_002
  Input url=http://second.co.jp; /
  Input url=http://www.google.com; /
  Input url=http://www.epaper.times.india.com; /
/TestCase
TestCase name=Sprint_003
  Input url=http://third.co.jp; /
  Input url=http://www.google.com; /
  Input url=http://www.epaper.times.india.com; /
/TestCase
/body
/opml



This my python code
from xml.etree import ElementTree



with open('our.xml', 'rt') as f:
  tree = ElementTree.parse(f)



for node, value in tree.findall('.//TestCase/Input'):



  url=node.attrib.get('url')
  print url



i want to print the url depending on name=sprint_001.


  for test_case in tree.findall('.//TestCase'):
  if test_case.get('name') == 'sprint_002':
 for input_el in test_case:
 print input_el.get('url')


i tried your logic i am not getting any out put for this


Obviously, because the correct name value is 'Sprint_002', not 
'sprint_002'. Please ask back if you need help in understanding the code I 
posted.


Stefan

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


Re: pickle unable to load collection

2010-05-18 Thread paragk
On May 18, 12:10 am, Peter Otten __pete...@web.de wrote:
 paragk wrote:
  Hi,

  I am unable to figure out the cause of python pickle unable to find
  the collection module.

  I am getting

      __import__(module)
  ImportError: No module named collections

  when I try to load a pickled object.

  Details:

  Python version:

  Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit
  (Intel)] on win32

  [CODE]

  import sys
  import glob
  import collections
  import pickle

  ...

  SomeListDict = collections.defaultdict(list)

  ... # Populate SomeListDict

  DictFile = open (options.saveDict, 'w')
  pickle.dump(SomeListDict , DictFile, -1)
  DictFile.close()

 [...]

  From the above analysis, clearly the collection module exists, since
  the dump works.

  What am I missing?

 You have to open the file in binary mode wb.

  import collections
  import pickle
  data = pickle.dumps(collections.defaultdict())
  pickle.loads(data)

 defaultdict(None, {})

 Now simulate the effect of writing in text mode and reading in binary mode:

  garbled_data = data.replace(\n, \r\n)
  pickle.loads(garbled_data)

 Traceback (most recent call last):
   File stdin, line 1, in module
   File /usr/lib/python2.6/pickle.py, line 1374, in loads
     return Unpickler(file).load()
   File /usr/lib/python2.6/pickle.py, line 858, in load
     dispatch[key](self)
   File /usr/lib/python2.6/pickle.py, line 1090, in load_global
     klass = self.find_class(module, name)
   File /usr/lib/python2.6/pickle.py, line 1124, in find_class
     __import__(module)
 ImportError: No module named collections

  try: pickle.loads(garbled_data)

 ... except ImportError as e:
 ...     e
 ...
 ImportError('No module named collections\r',)

 So as Steven suspected there was a whitespace char in the module name:
 pickle.load() was looking for the collections\r module.

 Peter

Thank you for the suggestions. Opening the file in 'wb' mode worked.

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


Re: Picking a license

2010-05-18 Thread Ed Keith
--- On Sat, 5/15/10, Ben Finney ben+pyt...@benfinney.id.au wrote:

 From: Ben Finney ben+pyt...@benfinney.id.au
 Subject: Re: Picking a license
 To: python-list@python.org
 Date: Saturday, May 15, 2010, 12:57 AM
 a...@pythoncraft.com
 (Aahz) writes:
 
  You can't really sell Open Source software in any
 practical way;
  someone will always undercut you once it's out in the
 wild. You can
  only sell support for the software, which is entirely
 different.
 
 Not at all. I've been selling all the software I write for
 clients for
 the past ten years, and it's all free software. It's been
 very practical
 for me and those I've worked with.
 
 You can't sell free software like selling loaves of bread,
 but that's a
 much more limited case and a far cry from your claim.
 Selling free
 software is quite practical and a good way to fund
 development of
 software that otherwise wouldn't be written as free
 software.
 
 -- 
  \     “Why am I an atheist? I ask
 you: Why is anybody not an atheist? |
   `\      Everyone starts out being an
 atheist.” —Andy Rooney, _Boston |
 _o__)             
                
                
   Globe_ 1982-05-30 |
 Ben Finney
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 

Why don't your own customers under cut you? If you sell someone GPLed 
software they have the right to redistribute it for less than you are 
distributing it for. That dose not strike me as a viable business model.

How do you make it work?

-EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com





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


Re: Picking a license

2010-05-18 Thread Ed Keith
--- On Sat, 5/15/10, Duncan Booth duncan.bo...@invalid.invalid wrote:

 From: Duncan Booth duncan.bo...@invalid.invalid
 Subject: Re: Picking a license
 To: python-list@python.org
 Date: Saturday, May 15, 2010, 8:52 AM
 Ed Keith e_...@yahoo.com
 wrote:
 
  I can not imagine anyone being stupid enough to pay me
 for rights to
  use code I had already published under the Boost
 License, which grants
  then the rights to do anything they want with it
 without paying me
  anything. 
    -EdK
  
 Really?
 
 The Boost License says, amongst other things:
 
  THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF
 ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
 TITLE AND
  NON-INFRINGEMENT. 
 
 Are you sure you can't imagine anyone offering to pay you
 for an 
 alternative license that came with some kind of warranty or
 support?
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 

Would that be a license or a support contract?

-EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com





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


Is there conversion method to convert pyunicodeobject to pybyteobject?

2010-05-18 Thread MathanK
Hi All,

A variable whose data type is PyUnicodeObject is to be assigned to varioable of 
PyBytesObject type 

example :

PyUnicodeObject *p = ...whatever...; 
function( (PyByteObject*p)); 

compiled and got a Bus Error.

Cheers,
Mathan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-18 Thread Ed Keith

--- On Sat, 5/15/10, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand 
wrote:

 From: Lawrence D'Oliveiro l...@geek-central.gen.new_zealand
 Subject: Re: Picking a license
 To: python-list@python.org
 Date: Saturday, May 15, 2010, 11:09 PM
 In message mailman.164.1273846256.32709.python-l...@python.org,
 Ed Keith 
 wrote:
 
  But if my client give someone else a copy of the
 binary I gave them, they
  are now in violation.
 
 Why would they be in violation? It seems to me a violation
 would only occur 
 if someone asked them for the source, and they refused.
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 

No, the GPL makes it clear that the responsibly is on the distributor to either 
supply the source or written notice, Caveat venditor. The violation exists 
regardless of whether or not the recipient makes a request.

   -EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com




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


Re: Picking a license

2010-05-18 Thread Ethan Furman

Paul Boddie wrote:
As I said before, spare me the condescension. 


Spare us your self-righteous bull-crap.

Do you think we haven't seen your false accusations and made-up motives 
against Patrick Maupin?  If I cared more and/or had more time, I'd make 
a summary -- but quite frankly Pat has defended himself quite well, 
while being very reasonable, and has said at least twice (more, I'm 
sure) that the choice of license is up to the author, and that there are 
good reasons for choosing any of the free licenses (including the GPL).


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


Convert PyUnicodeObject to PyBytesObject in python3.x?

2010-05-18 Thread gmail
Hi All,

A variable whose data type is PyUnicodeObject needs to passed to a function as 
an argument whose data type should be PyBytesObject type 

example :

PyUnicodeObject *p = ...whatever...; 
function (PyByteObject* a); 

function((PyBytesObject *)p);

compiled and got a Bus Error.

Thanks for spending ur valuable time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Conversion method for PyUnicodeObject type to PyBytesObject type

2010-05-18 Thread mathan kumar
A variable whose data type is PyUnicodeObject needs to be passed to a
function as an argument whose data type should be PyBytesObject type

example :
function (PyByteObject* a){
.operations
}
PyUnicodeObject *p = somevalue;
function((PyBytesObject *)p);

ouptut: Got a Bus Error.
-- 
http://mail.python.org/mailman/listinfo/python-list


Fw: Re: Re: joining files

2010-05-18 Thread mannu jha
Note: Forwarded message attached

-- Original Message --

From: mannu jhamannu_0...@rediffmail.com
To: tuomas.vesteri...@iki.fi
Subject: Re: Re: joining files---BeginMessage---
 import os
 def merge_sources(sources):
   # sources is a list of tuples (source_name, source_data)
   data = []
   keysets = []
   for nme, sce in sources:
lines = {}
for line in sce.split(os.linesep):
 lst = line.split()
 lines[lst[0]] = (nme, lst)
keysets.append(set(lines.keys()))
data.append(lines)
   common_keys = keysets[0]
   for keys in keysets[1:]:
common_keys = common_keys.intersection(keys)
   result = {}
   for key in common_keys:
result[key] = dict(d[key] for d in data if key in d)
   return result
 if __name__ == __main__:
   # Your test files here are replaced by local strings
   print merge_sources([(file1, file1), (file2, file2), (file3,

 file3)])
   print merge_sources([(input1, input1), (input2, input2)])
 Test_results = '''
 {'22': {'file3': ['22', 'C'],
'file2': ['22', '0'],
'file1': ['22', '110.1', '33', '331.5', '22.7', '5', '271.9'
  '17.2', '33.4']}}
 {'194': {'input2': ['194', 'C'],
'input1': ['194', '8.00', '121.23', '54.79', '4.12',
   '180.06']},
  '175': {'input2': ['175', 'H', '176', 'H', '180', 'H'],
'input1': ['175', '8.42', '120.50', '55.31', '4.04',
   '180.33']},
  '15': {'input2': ['15', 'H', '37', 'H', '95', 'T'],
'input1': ['15', '8.45', '119.04', '55.02', '4.08',
   '178.89']},
  '187': {'input2': ['187', 'H', '190', 'T'],
'input1': ['187', '7.79', '122.27', '54.37', '4.26',
   '179.75']}}
 Dear Sir,

 I tried above program but with that it is showing error:
 nmru...@caf:~ python join1.py
 Traceback (most recent call last):
  File join1.py, line 24, in
   print merge_sources([(file1, file1), (file2, file2), (file3,file3)])
 NameError: name 'file1' is not defined
 nmru...@caf:~
Add test data to the code as:
file1 = '''22 110.1 33 331.5 22.7 5 271.9 17.2 33.4
4 55.1'''
Thankyou very much sir it is working..Thankyou once again for your kind 
help. 

only one problem I am now facing i.e. when I tried to replace test data with 
filename 1.e.
file1 = open(input11.txt)
file2 = open(output22.txt)
print merge_sources([(file1, file1), (file2, file2)])
then it is showing error 

ph08...@linux-af0n:~ python new.py
Traceback (most recent call last):
  File new.py, line 25, in 
print merge_sources([(file1, file1), (file2, file2)])
  File new.py, line 9, in merge_sources
for line in sce.split(os.linesep):
AttributeError: 'file' object has no attribute 'split'
ph08...@linux-af0n:~ 

where my input11.txt is:
'''187 7.79 122.27 54.37 4.26 179.75
194 8.00 121.23 54.79 4.12 180.06
15 8.45 119.04 55.02 4.08 178.89
176 7.78 118.68 54.57 4.20 181.06
180 7.50 119.21 53.93 179.80
190 7.58 120.44 54.62 4.25 180.02
152 8.39 120.63 55.10 4.15 179.10
154 7.79 119.62 54.47 4.22 180.46
175 8.42 120.50 55.31 4.04 180.33'''

and output22.txt is:
'''15 H
37 H
95 T
124 H
130 H
152 H
154 H
158 H
164 H
175 H
176 H
180 H
187 H
190 T
194 C'''

since my files are very big hence i want to give filename as input.





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


python and GNU plot

2010-05-18 Thread Sandy Ydnas

 

pls pls help how to use Gnuplot 

 

Gnuplot runs from Python under Vista

 

downloaded  Gnuplot, but what they suggest only Run wgnuplot.exe

 

Thank you very much in advance!!!

 

Sandy
  
_
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


subprocess and gvfs-mount

2010-05-18 Thread Samuel Bancal
Hi,

I'm coding a script that does some automates for my users ... including
mounting a smb share.

Because we are using Gnome, I choosed to use gvfs-mount, which is quite
similar to Places  Connect to Server  ...

Now my script does :
print *** Mounting the FILER ...
cmd = /usr/bin/gvfs-mount smb://%s\;%...@myfiler.domain.ch/data/%s %
(my_domain, my_user_name, my_user_name)
try:
retCode = subprocess.call(cmd, shell=True)
except KeyboardInterrupt, e:
sys.stderr.write(Interrupted by ctrl-c. Exiting\n)
sys.exit(1)
if retCode != 0:
sys.stderr.write(Error while mounting : %s\n % retCode)

I have two major problems with this code :
- In case of ctr-c while the password is asked to the user, I get a
Terminal in which the output from keyboard is inhibited... (like while
typing password)
- When the user runs this script by double-click  Run (not Run in
terminal) ... there is no interaction with the user.

I also did some try with subprocess.Popen ... with no success yet...

Thanks for any comment or suggestion!

Regards,
Samuel Bancal

ps : Or anyone knows how to get that gvfs-mount in GUI mode... Could see
nautilus-connect-server ... but couldn't find any options.

-- 
Samuel Bancal - CH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: joining files

2010-05-18 Thread mannu jha


On Mon, 17 May 2010 23:57:18 +0530  wrote
Try:
file = open(input11.txt)
file1 = file.read() # file1 is a string
file.close()
or
file1 = open(input11.txt) # file1 is an open file object
and replace lines:
 for line in sce.split(os.linesep):
   lst = line.split()
   lines[lst[0]] = (nme, lst)
with lines:
 for line in sce:
   lst = line.split()
   lines[lst[0]] = (nme, lst)
 sce.close()


Thankyou very much sir it has worked. Thankyou once again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables for python applications

2010-05-18 Thread Duncan Booth
Steven D'Aprano st...@remove-this-cybersource.com.au wrote:

 I think it is an abuse of the term constant to allow you to talk about a 
 mutable object being constant, since it can vary. Generally, you don't 
 care about identity, only equality. Making up a syntax on the spot:
 
 constant pi = [3.1415]
 assert pi = 3.1415
 pi[0] = 3
 assert pi = 3.1415
 
 makes a mockery of the concept of a constant.

A better keyword might be something like 'alias' to imply that the name and 
value are interchangeable.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this an ok thing to do in a class

2010-05-18 Thread Simon Brunning
On 18 May 2010 06:21:32 UTC+1, Vincent Davis vinc...@vincentdavis.net wrote:

 Just wondering if there is a problem with mixing a dictionary into a class 
 like this. Everything seems to work as I would expect.

No problem at all AFAIC.

--
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


max time wait for a function

2010-05-18 Thread pacopyc
Hi, I've a question for you. I'd like to call a function and waiting
its return value for a time max (30 sec).
The function could not respond and then I must avoid to wait for
infinite time. OS is Windows XP.
Can you help me?

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


Re: max time wait for a function

2010-05-18 Thread Albert Hopkins
On Tue, 2010-05-18 at 02:45 -0700, pacopyc wrote:
 Hi, I've a question for you. I'd like to call a function and waiting
 its return value for a time max (30 sec).
 The function could not respond and then I must avoid to wait for
 infinite time. OS is Windows XP.
 Can you help me?
 
 Thank

This is how I do it with a function decorator. I probably borrowed this
from someone and not attributed it.  Anyway, it works on Linux, not sure
about Windows:

def function_timeout(seconds):
Function decorator to raise a timeout on a function call
import signal
class FunctionTimeOut(Exception):
pass

def decorate(f):
def timeout(signum, frame):
raise FunctionTimeOut()

def funct(*args, **kwargs):
old = signal.signal(signal.SIGALRM, timeout)
signal.alarm(seconds)

try:
result = f(*args, **kwargs)
finally:
signal.signal(signal.SIGALRM, old)
signal.alarm(0)
return result

return funct

return decorate


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


Re: Can't find _sqlite3.so in lib-dynload

2010-05-18 Thread Kushal Kumaran
On Tue, May 18, 2010 at 5:38 AM, Peng Yu pengyu...@gmail.com wrote:
 On May 17, 6:38 pm, a...@pythoncraft.com (Aahz) wrote:
 In article mailman.323.1274135213.32709.python-l...@python.org,
 Peng Yu  pengyu...@gmail.com wrote:



 I compiled python2.6.4 from source. But I can't find _sqlite3.so in
 the install directory. I thought that _sqlite3.so should be generated
 to the install directory.

 Would you please let me know how to fix it?

 Only if you provide some relevant details.  Such as, what OS?

 http://www.mikeash.com/getting_answers.html

 ubuntu.

Did the build process give a message at the end listing out the
modules it couldn't build?  Was _sqlite3 in that list?

Do you have the sqlite3 dev package installed?  With ubuntu, that's
the libsqlite3-dev package.

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


Re: subprocess and gvfs-mount

2010-05-18 Thread Adam Tauno Williams
On Mon, 2010-05-17 at 17:54 +0200, Samuel Bancal wrote:
 Hi,
 I'm coding a script that does some automates for my users ...
 including mounting a smb share.
 Because we are using Gnome, I choosed to use gvfs-mount, which is
 quite similar to Places  Connect to Server  ...=
 Now my script does :
 print *** Mounting the FILER ...
 cmd = /usr/bin/gvfs-mount smb://%s\;%
 s...@myfiler.domain.ch/data/%s % (my_domain, my_user_name, my_user_name)
 try:
 retCode = subprocess.call(cmd, shell=True)
 except KeyboardInterrupt, e:
 sys.stderr.write(Interrupted by ctrl-c. Exiting\n)
 sys.exit(1)
 if retCode != 0:
 sys.stderr.write(Error while mounting : %s\n % retCode
 I have two major problems with this code :
 - In case of ctr-c while the password is asked to the user, I get a
 Terminal in which the output from keyboard is inhibited... (like while
 typing password)
 - When the user runs this script by double-click  Run (not Run in
 terminal) ... there is no interaction with the user.

Which is normal [there is a run-in-terminal check box somewhere?].  If
your users are running it in GNOME then you should implement a GUI
(PyGTK) for the user interaction [prompting for the password].  Or
better use the GNOME keyring.

http://pypi.python.org/pypi/keyring

-- 
Adam Tauno Williams awill...@whitemice.org LPIC-1, Novell CLA
http://www.whitemiceconsulting.com
OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: max time wait for a function

2010-05-18 Thread Bryan
pacopyc  wrote:
 I'd like to call a function and waiting
 its return value for a time max (30 sec).
 The function could not respond and then I must avoid to wait for
 infinite time. OS is Windows XP.

You can do that using the multiprocessing module, which is in the
standard library of Python 2.6 or better. It has certain limitations,
but works on XP.

The functions have to be defined at module scope, and the arguments
and return value must be pickleable. The way multiprocessing works on
Windows, it launches a new process which runs the Python interpreter
on the module again, and pickles the arguments to pipe them to the new
process.

Below is a simple working demo/test. The demo uses a timeout of 1
second, rather than the specified 30, to avoid excessive boringness.
In practice, timeout_function() would be recklessly inefficient for
controlling quick operations; it creates a new pool of processes for
each function call that it might need to time-out. That's fixable, but
the question here is about a 30-second-plus processing problem, and in
that kind of case the overhead of creating one or a few new processes
is lost in the noise.

-Bryan Olson

#

from multiprocessing import Pool, TimeoutError

def timeout_function(timeout, f, args=(), kwargs={}):
 Return f(*args, **kwargs), or if that takes
to long raise multiprocessing.TimeoutError.

pool = Pool(1)
return pool.apply_async(f, args, kwargs).get(timeout)


#--
# simple demo-test:

from random import random as rand
from time import sleep

def sillyfunc(sleeptime):
# Time-absorbing function for testing
sleep(sleeptime)
return 'Done.'

if __name__ == '__main__':
timeout = 1.0
print Timeout is %f seconds % timeout
trials = 100
ntimeouts = 0
for _ in range(trials):

# time-out probability a bit over 0.5
sleeptime = rand() * timeout * 2

try:
result = timeout_function(
timeout,
sillyfunc,
(sleeptime,))
assert result == 'Done.'
print 'Ran without timing out'

except TimeoutError:
ntimeouts += 1
print 'Timed out'
if sleeptime  timeout:
print '...Sucks! Slept %f' % sleeptime

print 'Timed out %d out of %d' % (ntimeouts, trials)

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


Regular expression

2010-05-18 Thread Back9
 Hi,

I have a string like this:
0x340x5A0x9B0xBA
I want to extract 0x from the string but the first one.

How I can use re for this case?

The string size will vary.

TIA

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


Re: Regular expression

2010-05-18 Thread ilvecchio
On May 18, 3:48 pm, Back9 backgoo...@gmail.com wrote:
  Hi,

 I have a string like this:
 0x340x5A0x9B0xBA
 I want to extract 0x from the string but the first one.

 How I can use re for this case?

 The string size will vary.

 TIA

Maybe the easy way is something like this:

m = re.match('(0x)(.*)','0x340x5A0x9B0xBA')
m.groups()[1]

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


Re: Regular expression

2010-05-18 Thread Back9
On May 18, 10:09 am, ilvecchio terenzio.be...@gmail.com wrote:
 On May 18, 3:48 pm, Back9 backgoo...@gmail.com wrote:

   Hi,

  I have a string like this:
  0x340x5A0x9B0xBA
  I want to extract 0x from the string but the first one.

  How I can use re for this case?

  The string size will vary.

  TIA

 Maybe the easy way is something like this:

 m = re.match('(0x)(.*)','0x340x5A0x9B0xBA')
 m.groups()[1]

 Terenzio

I mean the result should be like this:
0x345A9BBA
-- 
http://mail.python.org/mailman/listinfo/python-list


Multi-Threading in Python

2010-05-18 Thread Lou
Can anyone tell me how easy it is to do multi-threading in Python?
This has probably been brought up already, so if it has, thanks anyway
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression

2010-05-18 Thread Jon Clements
On 18 May, 15:32, Back9 backgoo...@gmail.com wrote:
 On May 18, 10:09 am, ilvecchio terenzio.be...@gmail.com wrote:



  On May 18, 3:48 pm, Back9 backgoo...@gmail.com wrote:

    Hi,

   I have a string like this:
   0x340x5A0x9B0xBA
   I want to extract 0x from the string but the first one.

   How I can use re for this case?

   The string size will vary.

   TIA

  Maybe the easy way is something like this:

  m = re.match('(0x)(.*)','0x340x5A0x9B0xBA')
  m.groups()[1]

  Terenzio

 I mean the result should be like this:
 0x345A9BBA

Something like: re.sub(r'\B(0x)', '', s)


hth, Jon.

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


Re: Regular expression

2010-05-18 Thread J. Cliff Dyer
Don't use regular expressions for that.

s = '0x340x5A0x9B0xBA'
return '0x' + ''.join(s.split('0x'))

On Tue, 2010-05-18 at 06:48 -0700, Back9 wrote:
 Hi,
 
 I have a string like this:
 0x340x5A0x9B0xBA
 I want to extract 0x from the string but the first one.
 
 How I can use re for this case?
 
 The string size will vary.
 
 TIA
 


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


Re: Multi-Threading in Python

2010-05-18 Thread Adam Tauno Williams
On Tue, 2010-05-18 at 07:35 -0700, Lou wrote:
 Can anyone tell me how easy it is to do multi-threading in Python?

Very easy.  Or as easy as in any other platform - and as easy to screw
up.  Personally I prefer to use multiprocessing [which is a module that
'simulates' threads using separate processes].  IMO, it is hard to screw
up as you don't get any shared-state for free.

 This has probably been brought up already, so if it has, thanks anyway

-- 
Adam Tauno Williams awill...@whitemice.org LPIC-1, Novell CLA
http://www.whitemiceconsulting.com
OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: Is this an ok thing to do in a class

2010-05-18 Thread Bruno Desthuilliers

Simon Brunning a écrit :

On 18 May 2010 06:21:32 UTC+1, Vincent Davis vinc...@vincentdavis.net wrote:

Just wondering if there is a problem with mixing a dictionary into a class like 
this. Everything seems to work as I would expect.


No problem at all AFAIC.


OP didn't show up on c.l.py, so too bad you snipped the relevant code 
snippet...

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


Re: abc don't play well with private method

2010-05-18 Thread Bruno Desthuilliers

mouadino a écrit :

Hello
and thanx for your answer it's was very helpful

but just to clear some thinks :


There's no such thing as a private attribute in Python. The
name-mangling mechanism invoked by __name is really meant to avoid
accidental redefinition of the attribute in a derived class.



In this case, your attribute is expected to be redefined, so you
definitly don't want any name mangling here.


yes , but what i have supposed is that the name mangling will not be
applied when you use abc especially when you decorate the function
with abc.abstractmethod , because it's will(should) be redefined (so
something is wrong with the abc module) .


I agree this might be a bit inconsistant - or at least that your 
expectations were rather understandable. But well, that's how it is and 
you'll have to deal with it for at least a few years.


Now I bet the name_mangling mechanism is applied in such a way that 
implementing your expectations would be rather impractical or add way to 
much overhead. Specially when almost no one ever seem to find a use for 
this feature. As far as I'm concerned, I think I didn't used it more 
half a dozen times, for some very deep implementation detail of some 
miniframework, and mostly because I'm a bit on the paranoid side.





Also and FWIW, the naming convention for implementation attributes is
a single leading underscore


sorry but i don't agree on this.


So you disagree with the established convention followed by (wild guess) 
about 99.99% of the regulars here and applied in most of the existing 
python code base.





the two underscore (__) are used in
classes level for defining private method in the python way,


The __names are used to invoke name mangling on the attribute (whatever 
type it is). It doesn't make it private - just a bit less subject to 
accidental override. And - I have ton insist on this - it applies to 
every attribute. FWIW, Python's methods are really not what you may 
think they are !-)



and the
one underscore (_) is used in the module level :


... to avoid export such named symbols in the case of a wildcard import 
AND if the module didn't defined an __ALL__ attribute.


The _names are used to denote implementation attribute - IOW, don't 
touch unless you're ready to pay the price.



Prepending a single underscore (_) has some support for protecting
module variables and functions (not included with import * from).
Prepending a double underscore (__) to an instance variable or method
effectively serves to make the variable or method private to its class
(using name mangling). 
src:http://google-styleguide.googlecode.com/svn/trunk/pyguide.html


This is at best badly formulated and really needs a rewrite.

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


RE: Multi-Threading in Python

2010-05-18 Thread Sandy Ydnas


 great

can help to find some examples of multiprocessing 

Sandy
 Subject: Re: Multi-Threading in Python
 From: awill...@whitemice.org
 To: python-list@python.org
 Date: Tue, 18 May 2010 10:45:11 -0400
 
 On Tue, 2010-05-18 at 07:35 -0700, Lou wrote:
  Can anyone tell me how easy it is to do multi-threading in Python?
 
 Very easy. Or as easy as in any other platform - and as easy to screw
 up. Personally I prefer to use multiprocessing [which is a module that
 'simulates' threads using separate processes]. IMO, it is hard to screw
 up as you don't get any shared-state for free.
 
  This has probably been brought up already, so if it has, thanks anyway
 
 -- 
 Adam Tauno Williams awill...@whitemice.org LPIC-1, Novell CLA
 http://www.whitemiceconsulting.com
 OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
  
_
Hotmail: Free, trusted and rich email service.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Getting System error with PyModule_AddIntConstant funtion

2010-05-18 Thread MathanK
Following is a Python C api which runs properly without PyModule_AddIntConstant 
function. 


But when PyModule_AddIntConstant() function is used, getting the following 
error when i call 
c. path(test call);
 SystemError: NULL result without error in PyObject_Call 


Python C api- c.c


int test(int a){
 return (2*a+a);
 }
 

 PyObject* dict = NULL;
 

 static PyObject* path(PyObject* self, PyObject* args) {
 char *cpath;
 PyUnicodeObject *path;
 PyUnicodeObject *test; 
 

 if (!PyArg_ParseTuple(args, s, amp;path))
return NULL; 
 cpath = (char *)path; 
 test = (PyUnicodeObject*)(cpath); 
 PyObject *testDict = PyDict_New();
 int testVal = PyDict_SetItem(testDict, (PyObject 
*)PyUnicode_FromString(cpath), (PyObject *)PyUnicode_FromString(cpath));
  
 return Py_BuildValue(s, test);
 }
 static PyObject* c(PyObject* self, PyObject* args) {
 
 int a;
 int result;
if(!PyArg_ParseTuple(args, i, amp;a))
 return NULL;
 result = test(a);
 return Py_BuildValue(i, result);
  
 }
 

 static PyMethodDef cmethods[] = {
 {c, c, METH_VARARGS, watch},
 {path, path, METH_VARARGS, test},
 {NULL, NULL, 0, NULL},
 };
 

 static struct PyModuleDef c_Module = {
 PyModuleDef_HEAD_INIT,
 c,
 (
   Interface.
 ),
 -1,
 cmethods
 };
 

 PyMODINIT_FUNC PyInit_c(void) {
  
 PyObject* obj = PyModule_Create(amp;c_Module);
 long lon1 = 0;
 PyModule_AddIntConstant(obj, test, lon1);
 
 }
 

 int main(int argc, wchar_t *argv[])
 {
 PyImport_AppendInittab(c, PyInit_c);
 Py_SetProgramName(argv[0]);
 Py_Initialize();
 PyImport_ImportModule(c);
 return 0;
 }
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting System error with PyModule_AddIntConstant funtion

2010-05-18 Thread Philip Semanchuk


On May 18, 2010, at 11:41 AM, MathanK wrote:

Following is a Python C api which runs properly without  
PyModule_AddIntConstant function.



But when PyModule_AddIntConstant() function is used, getting the  
following error when i call

c. path(test call);
 SystemError: NULL result without error in PyObject_Call 


Hi Mathan,
You're not checking the return code from PyModule_Create(). Is it  
returning NULL?


Also, there's a list specific to Python's C API. You might get a  
better response to your question there:

http://mail.python.org/mailman/listinfo/capi-sig


bye
Philip





Python C api- c.c


int test(int a){
return (2*a+a);
}


PyObject* dict = NULL;


static PyObject* path(PyObject* self, PyObject* args) {
char *cpath;
PyUnicodeObject *path;
PyUnicodeObject *test;


if (!PyArg_ParseTuple(args, s, amp;path))
   return NULL;
cpath = (char *)path;
test = (PyUnicodeObject*)(cpath);
PyObject *testDict = PyDict_New();
int testVal = PyDict_SetItem(testDict, (PyObject  
*)PyUnicode_FromString(cpath), (PyObject  
*)PyUnicode_FromString(cpath));


return Py_BuildValue(s, test);
}
static PyObject* c(PyObject* self, PyObject* args) {

int a;
int result;
   if(!PyArg_ParseTuple(args, i, amp;a))
return NULL;
result = test(a);
return Py_BuildValue(i, result);

}


static PyMethodDef cmethods[] = {
{c, c, METH_VARARGS, watch},
{path, path, METH_VARARGS, test},
{NULL, NULL, 0, NULL},
};


static struct PyModuleDef c_Module = {
PyModuleDef_HEAD_INIT,
c,
(
  Interface.
),
-1,
cmethods
};


PyMODINIT_FUNC PyInit_c(void) {

PyObject* obj = PyModule_Create(amp;c_Module);
long lon1 = 0;
PyModule_AddIntConstant(obj, test, lon1);

}


int main(int argc, wchar_t *argv[])
{
PyImport_AppendInittab(c, PyInit_c);
Py_SetProgramName(argv[0]);
Py_Initialize();
PyImport_ImportModule(c);
return 0;
}
--
http://mail.python.org/mailman/listinfo/python-list


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


Re: getting attributes and methods of class without creating object

2010-05-18 Thread Terry Reedy

On 5/18/2010 2:11 AM, shuvro wrote:

to know the attributes of an instance of a class without
actually creating that instance is very difficult.



Is it not possible with the existing python facilities (without adding
external libraries) ?


To know what a function would do if you were to call it, without 
actually calling it, look at the function code with the dis (assembler) 
module.


#3.1
 import dis
 class C:
def __init__(self, a): self.a = a

 dis.dis(C.__init__)
  2   0 LOAD_FAST1 (a)
  3 LOAD_FAST0 (self)
  6 STORE_ATTR   0 (a)
  9 LOAD_CONST   0 (None)
 12 RETURN_VALUE

If you read the doc, or know assembler, you would see that the instance 
gets attribute a. Use dir(C) to find all the methods to disassemble.


Terry Jan Reedy

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


Re: Picking a license

2010-05-18 Thread Robert Kern

On 2010-05-16 09:25 , Ed Keith wrote:


--- On Sat, 5/15/10, Lawrence D'Oliveirol...@geek-central.gen.new_zealand  
wrote:


From: Lawrence D'Oliveirol...@geek-central.gen.new_zealand
Subject: Re: Picking a license
To: python-list@python.org
Date: Saturday, May 15, 2010, 11:09 PM
In messagemailman.164.1273846256.32709.python-l...@python.org,
Ed Keith
wrote:


But if my client give someone else a copy of the

binary I gave them, they

are now in violation.


Why would they be in violation? It seems to me a violation
would only occur
if someone asked them for the source, and they refused.
--
http://mail.python.org/mailman/listinfo/python-list



No, the GPL makes it clear that the responsibly is on the distributor to either 
supply the source or written notice, Caveat venditor. The violation exists 
regardless of whether or not the recipient makes a request.


No, one of the options for you is that you make the source available upon 
request.

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Multi-Threading in Python

2010-05-18 Thread geremy condra
On Tue, May 18, 2010 at 7:35 AM, Lou louro...@gmail.com wrote:
 Can anyone tell me how easy it is to do multi-threading in Python?
 This has probably been brought up already, so if it has, thanks anyway
 --
 http://mail.python.org/mailman/listinfo/python-list

It's very easy, but it's probably best to use multiple processes to take
advantage of multiple cores. Take a look at the threading and
multiprocessing modules.

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


Discover PyH

2010-05-18 Thread bluesmanu
Hi all,

I would like to present my first python library : PyH.
PyH is a concise and powerful module that lets you build your HTML
pages like a GUI. Tags are objects that can be created, included and
modified at any time during your script.
Discover it at http://pyh.googlecode.com .
You can file bug reports and feature requests at https://launchpad.net/pyh
.

Cheers,

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


Re: Is there conversion method to convert pyunicodeobject to pybyteobject?

2010-05-18 Thread Terry Reedy

On 5/15/2010 10:50 AM, MathanK wrote:

This is the third time, at least, that you posted this, though the first 
time you asked a question. You have given no indication that you 
bothered to look in the manual before or between postings.



A variable whose data type is PyUnicodeObject is to be assigned to
varioable of PyBytesObject type

example :

PyUnicodeObject *p = ...whatever...;
function( (PyByteObject*p));


C casting is usually not conversion. It says pretend that the data is 
another type, even though it is not. Only use it when you actually know 
what you are doing.



compiled and got a Bus Error.


In Python, b = p.encode('utf-8') or whatever encoding you want. Look in 
the C-API manual for the CPython function that actually does this.


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


Re: max time wait for a function

2010-05-18 Thread Terry Reedy

On 5/18/2010 6:24 AM, Albert Hopkins wrote:

On Tue, 2010-05-18 at 02:45 -0700, pacopyc wrote:

Hi, I've a question for you. I'd like to call a function and waiting
its return value for a time max (30 sec).
The function could not respond and then I must avoid to wait for
infinite time. OS is Windows XP.
Can you help me?

Thank


This is how I do it with a function decorator. I probably borrowed this
from someone and not attributed it.  Anyway, it works on Linux, not sure
about Windows:

def function_timeout(seconds):
 Function decorator to raise a timeout on a function call
 import signal
 class FunctionTimeOut(Exception):
 pass

 def decorate(f):
 def timeout(signum, frame):
 raise FunctionTimeOut()

 def funct(*args, **kwargs):
 old = signal.signal(signal.SIGALRM, timeout)
 signal.alarm(seconds)


from help(signal):
alarm() -- cause SIGALRM after a specified time [Unix only]

I do not know of any replacement in the stdlib, but one could check the 
code for multiprocessing to see how it does a timeout. Or check the 
pywin32 library

http://pypi.python.org/pypi/pywin32/210


 try:
 result = f(*args, **kwargs)
 finally:
 signal.signal(signal.SIGALRM, old)
 signal.alarm(0)
 return result

 return funct

 return decorate





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


Re: Multi-Threading in Python

2010-05-18 Thread Terry Reedy

On 5/18/2010 11:29 AM, Sandy Ydnas wrote:


can help to find some examples of multiprocessing


Multiprocessing is designed to be api-compatible with threading.
Search the archives of this list/newsgroup for several examples.


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


RE: Multi-Threading in Python

2010-05-18 Thread Adam Tauno Williams
On Tue, 2010-05-18 at 20:29 +0500, Sandy Ydnas wrote:
  great
 can help to find some examples of multiprocessing 

There is the reasonably good documentation at:
http://docs.python.org/library/multiprocessing.html

I did a Multiprocessing presentation recently:
http://groups.google.com/group/grpug/web/Multiprocessing.pdf

And I use multiprocessing in my project;  but less than previously as I
now use AMQ for the IPC and multiprocessing only for the process
management.
http://coils.hg.sourceforge.net/hgweb/coils/coils/file/af60dd17fa0e
But an entire project is quite a bit to pick through.

  Subject: Re: Multi-Threading in Python
  From: awill...@whitemice.org
  To: python-list@python.org
  Date: Tue, 18 May 2010 10:45:11 -0400
  
  On Tue, 2010-05-18 at 07:35 -0700, Lou wrote:
   Can anyone tell me how easy it is to do multi-threading in Python?
  
  Very easy. Or as easy as in any other platform - and as easy to
 screw
  up. Personally I prefer to use multiprocessing [which is a module
 that
  'simulates' threads using separate processes]. IMO, it is hard to
 screw
  up as you don't get any shared-state for free.
  
   This has probably been brought up already, so if it has, thanks
 anyway
  
  -- 
  Adam Tauno Williams awill...@whitemice.org LPIC-1, Novell CLA
  http://www.whitemiceconsulting.com
  OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba
  
  -- 
  http://mail.python.org/mailman/listinfo/python-list
 
 
 __
 Hotmail: Free, trusted and rich email service. Get it now.


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


Re: Picking a license

2010-05-18 Thread Ed Keith
--- On Tue, 5/18/10, Robert Kern robert.k...@gmail.com wrote:

 From: Robert Kern robert.k...@gmail.com
 Subject: Re: Picking a license
 To: python-list@python.org
 Date: Tuesday, May 18, 2010, 12:03 PM
 On 2010-05-16 09:25 , Ed Keith
 wrote:
 
  --- On Sat, 5/15/10, Lawrence D'Oliveirol...@geek-central.gen.new_zealand 
 wrote:
 
  From: Lawrence D'Oliveirol...@geek-central.gen.new_zealand
  Subject: Re: Picking a license
  To: python-list@python.org
  Date: Saturday, May 15, 2010, 11:09 PM
  In messagemailman.164.1273846256.32709.python-l...@python.org,
  Ed Keith
  wrote:
 
  But if my client give someone else a copy of
 the
  binary I gave them, they
  are now in violation.
 
  Why would they be in violation? It seems to me a
 violation
  would only occur
  if someone asked them for the source, and they
 refused.
  --
  http://mail.python.org/mailman/listinfo/python-list
 
 
  No, the GPL makes it clear that the responsibly is on
 the distributor to either supply the source or written
 notice, Caveat venditor. The violation exists regardless of
 whether or not the recipient makes a request.
 
 No, one of the options for you is that you make the source
 available upon request.
 

But I am required to give written notice to that effect.

   -EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com



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


Re: pickle unable to load collection

2010-05-18 Thread Terry Reedy

On 5/18/2010 3:10 AM, Peter Otten wrote:

Now simulate the effect of writing in text mode and reading in binary mode:


  garbled_data = data.replace(\n, \r\n)
  pickle.loads(garbled_data)

Traceback (most recent call last):

...

ImportError: No module named collections


  try: pickle.loads(garbled_data)

... except ImportError as e:
... e
...
ImportError('No module named collections\r',)


Nice catch, Peter. I filed a request that the message quote the name it 
cannot import, so that the OP would have seen the more informative


ImportError: No module named 'collections\r'

http://bugs.python.org/issue8754

Terry Jan Reedy


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


RE: Multi-Threading in Python

2010-05-18 Thread Sandy Ydnas

good 

thanks a lot

Sandy
 
 Subject: RE: Multi-Threading in Python
 From: awill...@whitemice.org
 To: python-list@python.org
 Date: Tue, 18 May 2010 12:45:37 -0400
 
 On Tue, 2010-05-18 at 20:29 +0500, Sandy Ydnas wrote:
  great
  can help to find some examples of multiprocessing 
 
 There is the reasonably good documentation at:
 http://docs.python.org/library/multiprocessing.html
 
 I did a Multiprocessing presentation recently:
 http://groups.google.com/group/grpug/web/Multiprocessing.pdf
 
 And I use multiprocessing in my project; but less than previously as I
 now use AMQ for the IPC and multiprocessing only for the process
 management.
 http://coils.hg.sourceforge.net/hgweb/coils/coils/file/af60dd17fa0e
 But an entire project is quite a bit to pick through.
 
   Subject: Re: Multi-Threading in Python
   From: awill...@whitemice.org
   To: python-list@python.org
   Date: Tue, 18 May 2010 10:45:11 -0400
   
   On Tue, 2010-05-18 at 07:35 -0700, Lou wrote:
Can anyone tell me how easy it is to do multi-threading in Python?
   
   Very easy. Or as easy as in any other platform - and as easy to
  screw
   up. Personally I prefer to use multiprocessing [which is a module
  that
   'simulates' threads using separate processes]. IMO, it is hard to
  screw
   up as you don't get any shared-state for free.
   
This has probably been brought up already, so if it has, thanks
  anyway
   
   -- 
   Adam Tauno Williams awill...@whitemice.org LPIC-1, Novell CLA
   http://www.whitemiceconsulting.com
   OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba
   
   -- 
   http://mail.python.org/mailman/listinfo/python-list
  
  
  __
  Hotmail: Free, trusted and rich email service. Get it now.
 
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
  
_
Hotmail: Trusted email with powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression

2010-05-18 Thread Terry Reedy

On 5/18/2010 10:40 AM, J. Cliff Dyer wrote:

Don't use regular expressions for that.

s = '0x340x5A0x9B0xBA'
return '0x' + ''.join(s.split('0x'))


or
 '0x'+s[2:].replace('0x','')
'0x345A9BBA'

Take your pick, you should learn and understand both.


On Tue, 2010-05-18 at 06:48 -0700, Back9 wrote:

Hi,

I have a string like this:
0x340x5A0x9B0xBA
I want to extract 0x from the string but the first one.

How I can use re for this case?

The string size will vary.

TIA







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


Re: Picking a license

2010-05-18 Thread Patrick Maupin
On May 18, 11:03 am, Robert Kern robert.k...@gmail.com wrote:
 On 2010-05-16 09:25 , Ed Keith wrote:
  No, the GPL makes it clear that the responsibly is on the distributor to 
  either supply the source or written notice, Caveat venditor. The violation 
  exists regardless of whether or not the recipient makes a request.

 No, one of the options for you is that you make the source available upon 
 request.

Do you have a citation for that?  My reading, of both GPL v2 section 3
and GPL v3 section 6, is that someone distributing GPL licensed object
must do one of the following:

- supply the source with the object
- supply a written offer for source with the object
- supply a copy of someone else's written offer for source with the
object (only allowed sometimes)
- Perhaps verbally communicate an offer (GPL v2 only, very liberal
reading of 3c, but even then the communication must accompany the
object distribution).
- supply object by offering access from a designated place as long
as you offer equivalent access to the Corresponding Source in the
same way through the same place or you maintain clear directions
next to the object code saying where to find the Corresponding
Source.

That last one effectively has written offer defined in a slightly
different way (maintain clear directions), and also might allow you
to just have a pile of source DVDs adjacent to a pile of object CDs
with no explicit written offer, but I honestly can't see how even that
can be stretched to cover just handing somebody an object CD without
even mentioning that source is available, and then only later giving
them source if they explicitly ask for it.

Sure, if you give somebody source after they ask for it, you have
probably cured any violation, but I think the very act of handing
someone an object CD without source or a written offer of source would
put you in violation of the license at the time you give them the
object CD.  It may be that saying oh, by the way, source code's
available if you want it would suffice in some cases under GPL v2,
but it doesn't look like that would work at all for GPL v3.

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


Re: Getting System error with PyModule_AddIntConstant funtion

2010-05-18 Thread MathanK
I checked for Null also. But No change in the result. Still getting the system 
error.
But when i m calling only c.c(5) function and not calling c.path(hi python c 
api) function, i m getting proper output without any system error.
Any clue? 
 
 Subject: Re: Getting System error with PyModule_AddIntConstant funtion
 From: Philip Semanchuk lt;phi...@semanchuk.comgt;
 Date: Tue, 18 May 2010 11:50:46 -0400
 To: python-list (General) lt;python-list@python.orggt;
 
 - Contents -
 
 
 On May 18, 2010, at 11:41 AM, MathanK wrote: 
 
 gt; Following is a Python C api which runs properly without 
 gt; PyModule_AddIntConstant function. 
 gt; 
 gt; 
 gt; But when PyModule_AddIntConstant() function is used, getting the 
 gt; following error when i call 
 gt; c. path(test call); 
 gt;  SystemError: NULL result without error in PyObject_Call  
 
 Hi Mathan, 
 You're not checking the return code from PyModule_Create(). Is it 
 returning NULL? 
 
 Also, there's a list specific to Python's C API. You might get a 
 better response to your question there: 
 http://mail.python.org/mailman/listinfo/capi-sig 
 
 
 bye 
 Philip 
 
 
 gt; 
 gt; 
 gt; Python C api- c.c 
 gt; 
 gt; 
 gt; int test(int a){ 
 gt; return (2*a+a); 
 gt; } 
 gt; 
 gt; 
 gt; PyObject* dict = NULL; 
 gt; 
 gt; 
 gt; static PyObject* path(PyObject* self, PyObject* args) { 
 gt; char *cpath; 
 gt; PyUnicodeObject *path; 
 gt; PyUnicodeObject *test; 
 gt; 
 gt; 
 gt; if (!PyArg_ParseTuple(args, s, amp;amp;path)) 
 gt; return NULL; 
 gt; cpath = (char *)path; 
 gt; test = (PyUnicodeObject*)(cpath); 
 gt; PyObject *testDict = PyDict_New(); 
 gt; int testVal = PyDict_SetItem(testDict, (PyObject 
 gt; *)PyUnicode_FromString(cpath), (PyObject 
 gt; *)PyUnicode_FromString(cpath)); 
 gt; 
 gt; return Py_BuildValue(s, test); 
 gt; } 
 gt; static PyObject* c(PyObject* self, PyObject* args) { 
 gt; 
 gt; int a; 
 gt; int result; 
 gt; if(!PyArg_ParseTuple(args, i, amp;amp;a)) 
 gt; return NULL; 
 gt; result = test(a); 
 gt; return Py_BuildValue(i, result); 
 gt; 
 gt; } 
 gt; 
 gt; 
 gt; static PyMethodDef cmethods[] = { 
 gt; {c, c, METH_VARARGS, watch}, 
 gt; {path, path, METH_VARARGS, test}, 
 gt; {NULL, NULL, 0, NULL}, 
 gt; }; 
 gt; 
 gt; 
 gt; static struct PyModuleDef c_Module = { 
 gt; PyModuleDef_HEAD_INIT, 
 gt; c, 
 gt; ( 
 gt; Interface. 
 gt; ), 
 gt; -1, 
 gt; cmethods 
 gt; }; 
 gt; 
 gt; 
 gt; PyMODINIT_FUNC PyInit_c(void) { 
 gt; 
 gt; PyObject* obj = PyModule_Create(amp;amp;c_Module); 
 gt; long lon1 = 0; 
 gt; PyModule_AddIntConstant(obj, test, lon1); 
 gt; 
 gt; } 
 gt; 
 gt; 
 gt; int main(int argc, wchar_t *argv[]) 
 gt; { 
 gt; PyImport_AppendInittab(c, PyInit_c); 
 gt; Py_SetProgramName(argv[0]); 
 gt; Py_Initialize(); 
 gt; PyImport_ImportModule(c); 
 gt; return 0; 
 gt; }
-- 
http://mail.python.org/mailman/listinfo/python-list


recall function definition from shell

2010-05-18 Thread superpollo

 def myfun():
... return WOW
...
 myfun()
'WOW'


now, i would like to list the funcion definition, something like this:

 myfun.somethinglikethis()
def myfun():
return WOW


is there something like this around?

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


upgrade python

2010-05-18 Thread packet
Would it be safe to upgrade from python 2.6.4 to 2.6.5 without hurting 
the 2.6.4?



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


Re: recall function definition from shell

2010-05-18 Thread Patrick Maupin
On May 18, 12:31 pm, superpollo ute...@esempio.net wrote:
   def myfun():
 ...     return WOW
 ...
   myfun()
 'WOW'
  

 now, i would like to list the funcion definition, something like this:

   myfun.somethinglikethis()
 def myfun():
      return WOW
  

 is there something like this around?

 bye

Sure, just give it a docstring and then you can call help on it:

 def myfun():
... ''' myfun returns WOW when called.
... This is just a Python __doc__ string
... '''
... return WOW
...
 help(myfun)

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


Re: recall function definition from shell

2010-05-18 Thread superpollo

Patrick Maupin ha scritto:

On May 18, 12:31 pm, superpollo ute...@esempio.net wrote:

  def myfun():
... return WOW
...
  myfun()
'WOW'
 

now, i would like to list the funcion definition, something like this:

  myfun.somethinglikethis()
def myfun():
 return WOW
 

is there something like this around?

bye


Sure, just give it a docstring and then you can call help on it:


def myfun():

... ''' myfun returns WOW when called.
... This is just a Python __doc__ string
... '''
... return WOW
...

help(myfun)


Regards,
Pat


mmm... thanks but not quite what i meant :-(

bye

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


Re: recall function definition from shell

2010-05-18 Thread Patrick Maupin
On May 18, 1:41 pm, superpollo ute...@esempio.net wrote:
 Patrick Maupin ha scritto:



  On May 18, 12:31 pm, superpollo ute...@esempio.net wrote:
    def myfun():
  ...     return WOW
  ...
    myfun()
  'WOW'

  now, i would like to list the funcion definition, something like this:

    myfun.somethinglikethis()
  def myfun():
       return WOW

  is there something like this around?

  bye

  Sure, just give it a docstring and then you can call help on it:

  def myfun():
  ...     ''' myfun returns WOW when called.
  ...         This is just a Python __doc__ string
  ...     '''
  ...     return WOW
  ...
  help(myfun)

  Regards,
  Pat

 mmm... thanks but not quite what i meant :-(

 bye

Well, I don't think Python remembers exactly how you typed it in, but
you can always ask Python for what it remembers about the function:

 def myfun():
... return WOW
...
 import dis
 dis.dis(myfun)
  2   0 LOAD_CONST   1 ('WOW')
  3 RETURN_VALUE


The inspect module is useful, as well.  But AFAIK Python doesn't
remember the source code for stuff you typed in.  (For functions in
imported modules, there is sufficient information remembered for
tracebacks to allow you to print out the lines of a function.)

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


Re: recall function definition from shell

2010-05-18 Thread superpollo

Patrick Maupin ha scritto:

On May 18, 1:41 pm, superpollo ute...@esempio.net wrote:

Patrick Maupin ha scritto:




On May 18, 12:31 pm, superpollo ute...@esempio.net wrote:

  def myfun():
... return WOW
...
  myfun()
'WOW'
now, i would like to list the funcion definition, something like this:
  myfun.somethinglikethis()
def myfun():
 return WOW
is there something like this around?
bye

Sure, just give it a docstring and then you can call help on it:

def myfun():

... ''' myfun returns WOW when called.
... This is just a Python __doc__ string
... '''
... return WOW
...

help(myfun)

Regards,
Pat

mmm... thanks but not quite what i meant :-(

bye


Well, I don't think Python remembers exactly how you typed it in


yes python does not, but maybe the *shell* does, or so i thought. i just 
wanted to dump the code for the function in a file, after i tested in 
the shell...



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


Re: recall function definition from shell

2010-05-18 Thread Peter Otten
superpollo wrote:

 Patrick Maupin ha scritto:
 On May 18, 1:41 pm, superpollo ute...@esempio.net wrote:
 Patrick Maupin ha scritto:



 On May 18, 12:31 pm, superpollo ute...@esempio.net wrote:
   def myfun():
 ... return WOW
 ...
   myfun()
 'WOW'
 now, i would like to list the funcion definition, something like
 this:
   myfun.somethinglikethis()
 def myfun():
  return WOW
 is there something like this around?
 bye
 Sure, just give it a docstring and then you can call help on it:
 def myfun():
 ... ''' myfun returns WOW when called.
 ... This is just a Python __doc__ string
 ... '''
 ... return WOW
 ...
 help(myfun)
 Regards,
 Pat
 mmm... thanks but not quite what i meant :-(

 bye
 
 Well, I don't think Python remembers exactly how you typed it in
 
 yes python does not, but maybe the *shell* does, or so i thought. i just
 wanted to dump the code for the function in a file, after i tested in
 the shell...

You could try ipython:

$ ipython
Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
Type copyright, credits or license for more information.

IPython 0.10 -- An enhanced Interactive Python.
? - Introduction and overview of IPython's features.
%quickref - Quick reference.
help  - Python's own help system.
object?   - Details about 'object'. ?object also works, ?? prints more.

In [1]: def f():
   ...: return 42
   ...:

In [2]: f()
Out[2]: 42

In [3]: %save tmp.py 1
The following commands were written to file `tmp.py`:
def f():
return 42


In [4]:
Do you really want to exit ([y]/n)?
$ cat tmp.py
def f():
return 42
$

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


Re: pickle unable to load collection

2010-05-18 Thread Peter Otten
Terry Reedy wrote:

 Nice catch, Peter. I filed a request that the message quote the name it
 cannot import, so that the OP would have seen the more informative
 
 ImportError: No module named 'collections\r'
 
 http://bugs.python.org/issue8754

Good idea; thank you for taking the initiative.

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


Re: recall function definition from shell

2010-05-18 Thread superpollo

Peter Otten ha scritto:

superpollo wrote:


Patrick Maupin ha scritto:

On May 18, 1:41 pm, superpollo ute...@esempio.net wrote:

Patrick Maupin ha scritto:




On May 18, 12:31 pm, superpollo ute...@esempio.net wrote:

  def myfun():
... return WOW
...
  myfun()
'WOW'
now, i would like to list the funcion definition, something like
this:
  myfun.somethinglikethis()
def myfun():
 return WOW
is there something like this around?
bye

Sure, just give it a docstring and then you can call help on it:

def myfun():

... ''' myfun returns WOW when called.
... This is just a Python __doc__ string
... '''
... return WOW
...

help(myfun)

Regards,
Pat

mmm... thanks but not quite what i meant :-(

bye

Well, I don't think Python remembers exactly how you typed it in

yes python does not, but maybe the *shell* does, or so i thought. i just
wanted to dump the code for the function in a file, after i tested in
the shell...


You could try ipython:

$ ipython
Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
Type copyright, credits or license for more information.

IPython 0.10 -- An enhanced Interactive Python.
? - Introduction and overview of IPython's features.
%quickref - Quick reference.
help  - Python's own help system.
object?   - Details about 'object'. ?object also works, ?? prints more.

In [1]: def f():
   ...: return 42
   ...:

In [2]: f()
Out[2]: 42

In [3]: %save tmp.py 1
The following commands were written to file `tmp.py`:
def f():
return 42


In [4]:
Do you really want to exit ([y]/n)?
$ cat tmp.py
def f():
return 42
$

Peter


RUNS TO APT-GET

hey great! thanks a lot!

best regards

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


Re: recall function definition from shell

2010-05-18 Thread Ethan Furman

superpollo wrote:

Patrick Maupin ha scritto:

On May 18, 1:41 pm, superpollo ute...@esempio.net wrote:

Patrick Maupin ha scritto:




On May 18, 12:31 pm, superpollo ute...@esempio.net wrote:

  def myfun():
... return WOW
...
  myfun()
'WOW'
now, i would like to list the funcion definition, something like 
this:

  myfun.somethinglikethis()
def myfun():
 return WOW
is there something like this around?
bye

Sure, just give it a docstring and then you can call help on it:

def myfun():

... ''' myfun returns WOW when called.
... This is just a Python __doc__ string
... '''
... return WOW
...

help(myfun)

Regards,
Pat

mmm... thanks but not quite what i meant :-(

bye


Well, I don't think Python remembers exactly how you typed it in


yes python does not, but maybe the *shell* does, or so i thought. i just 
wanted to dump the code for the function in a file, after i tested in 
the shell...


Take a look at ipython -- it has many enhancements: ipython.scipy.org

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


Re: recall function definition from shell

2010-05-18 Thread René 'Necoro' Neumann
Am 18.05.2010 20:55, schrieb superpollo:
 
 yes python does not, but maybe the *shell* does, or so i thought. i just
 wanted to dump the code for the function in a file, after i tested in
 the shell...

You might want to have a look at the IPython shell [1]. I personally do
not use it myself, but I thought to remember that it had some feature
like this (perhaps not dump _one function_, but all the input, which you
then only need to cleanup).

A quick glance revealed f.ex. the history and edit functionality [2] --
a bit more digging might really show up the thing you are looking for.

- René

[1] http://ipython.scipy.org/
[2]
http://ipython.scipy.org/doc/manual/html/interactive/tutorial.html#source-code-handling-tips




signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-18 Thread Ethan Furman

Ben Finney wrote:

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


Ben Finney  ben+pyt...@benfinney.id.au wrote:

[It is impractical to] sell free software like selling loaves of
bread, but that's a much more limited case and a far cry from your
claim [that it's impractical to sell free software]. Selling free
software is quite practical and a good way to fund development of
software that otherwise wouldn't be written as free software.

From my POV, if you're not selling COTS, you're really selling support
and consulting services, because that's what keeps your competitors
from just picking up your software and reselling it for cheaper. BTDT.


This thread has revealed some staggering gulfs in concepts as held by
different people. For example, I don't think it's at all germane to the
definition of “sell FOO” that “your competitors can pick up the FOO and
resell it cheaper”. Whether they can or not, that doesn't change that
fact that one is selling FOO.

Moreover, I don't try to prevent my competitors from reselling the
software (so long as they don't misrepresent who holds copyright or
further restrict the terms). That's part and parcel of the freedoms in
the software. Indeed, I find that helps the customers trust me more and
tend to come back when they want something else new; and my customers
are free to show others the solutions I've already implemented.

Thus is an ongoing business relationship crafted, including return
customers and referrals for new work. It really is practical to sell
free software.



This doesn't make sense to me, but I'm willing to learn -- how do you do 
this in practice?  Are you really selling the software, or rather 
selling things like setup, support, new code (or time to code), etc?


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


Re: Is this an ok thing to do in a class

2010-05-18 Thread Vincent Davis
Thanks for the feed back

Vincent

On Tue, May 18, 2010 at 8:50 AM, Bruno Desthuilliers
bruno.42.desthuilli...@websiteburo.invalid wrote:

 Simon Brunning a écrit :

 On 18 May 2010 06:21:32 UTC+1, Vincent Davis vinc...@vincentdavis.net
 wrote:

 Just wondering if there is a problem with mixing a dictionary into a
 class like this. Everything seems to work as I would expect.


 No problem at all AFAIC.


 OP didn't show up on c.l.py, so too bad you snipped the relevant code
 snippet...

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


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


setting variables in pdb

2010-05-18 Thread Art
If I am in Pdb, I would like to set a temporary variable, for example:

(Pdb) r = 1

The 'r' gets interpreted as 'return' by Pdb.

Is there a Pdb instruction that guarantees the intended effect, like:

(Pdb) let r = 1

I can usually avoid using such variable names, but if I am changing
the value of a local variable, it is convenient to be able to make
sure that trying to change that variable doesn't unintentionally call
a Pdb routine.

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


Re: Is this an ok thing to do in a class

2010-05-18 Thread Ethan Furman

Vincent Davis wrote:
Just wondering if there is a problem with mixing a dictionary into a 
class like this. Everything seems to work as I would expect.


class foo(object):
def __init__(self, x):
self.letter = dict(a=1,b=2,c=3)
self.A=self.letter['a']
self.x=self.letter[x]

  afoo = foo('b')
  afoo.x
2
  afoo.A
1
  afoo.letter['a']
1
  afoo.letter.items()
[('a', 1), ('c', 3), ('b', 2)]


Do you expect afoo.letter[x] to always be afoo.x?  Because they aren't:

 afoo.A = 9
 afoo.letter['a']
1

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


Re: setting variables in pdb

2010-05-18 Thread John Posner

On 5/18/2010 4:15 PM, Art wrote:

If I am in Pdb, I would like to set a temporary variable, for example:

(Pdb) r = 1

The 'r' gets interpreted as 'return' by Pdb.

Is there a Pdb instruction that guarantees the intended effect, like:

(Pdb) let r = 1

I can usually avoid using such variable names, but if I am changing
the value of a local variable, it is convenient to be able to make
sure that trying to change that variable doesn't unintentionally call
a Pdb routine.



Try setting *two* values at the interactive prompt:

   foo, r = 0, 3456

Variable r now has the value 3456.

HTH,
John


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


Re: setting variables in pdb

2010-05-18 Thread Duncan Booth
Art grenan...@gmail.com wrote:

 If I am in Pdb, I would like to set a temporary variable, for example:
 
 (Pdb) r = 1
 
 The 'r' gets interpreted as 'return' by Pdb.
 
 Is there a Pdb instruction that guarantees the intended effect, like:
 
 (Pdb) let r = 1

(Pdb) exec r=1
-- 
http://mail.python.org/mailman/listinfo/python-list


how to cause a request for a missing class attribute cause its calculation

2010-05-18 Thread Vincent Davis
Lets say I have
class foo(object):
def __init__(self, x, y):
self.x=x
self.y=y
def xplusy(self):
self.xy = x+y

inst = foo(1,2)
inst.xy   # no value, but I what this to cause the calculation of inst.xy

I don't what to have self.xy calculated before it is called.


Thanks

*Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this an ok thing to do in a class

2010-05-18 Thread Vincent Davis
On Tue, May 18, 2010 at 2:41 PM, Ethan Furman et...@stoneleaf.us wrote:

 Do you expect afoo.letter[x] to always be afoo.x?  Because they aren't:

  afoo.A = 9
  afoo.letter['a']
 1


What you are pointing out is that the assignment is not reversed . But that
does make me thing of something I had not.

 afoo.letter['a'] = 345
 afoo.A
1

Thats kinda a bummer, whats a good way to make sure affo.A gets updated?

Vincent


 ~Ethan~

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


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to cause a request for a missing class attribute cause its calculation

2010-05-18 Thread Chris Rebert
On Tue, May 18, 2010 at 1:39 PM, Vincent Davis vinc...@vincentdavis.net wrote:

 Lets say I have
 class foo(object):
     def __init__(self, x, y):
         self.x=x
         self.y=y
     def xplusy(self):
         self.xy = x+y
 inst = foo(1,2)
 inst.xy   # no value, but I what this to cause the calculation of inst.xy
 I don't what to have self.xy calculated before it is called.

class Foo(object):
def __init__(self, x, y):
self.x = x
self.y = y

@property
def xy(self):
'''Will calculate x+y every time'''
return self.x + self.y

Or if Foo is immutable and you wish to cache x+y:

class Foo(object):
def __init__(self, x, y):
self.x = x
self.y = y
self._xy = None

@property
def xy(self):
if self._xy is None:
self._xy = self.x + self.y
return self._xy

Suggested reading: http://docs.python.org/library/functions.html#property

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this an ok thing to do in a class

2010-05-18 Thread Ethan Furman

Vincent Davis wrote:
On Tue, May 18, 2010 at 2:41 PM, Ethan Furman et...@stoneleaf.us 
mailto:et...@stoneleaf.us wrote:


Do you expect afoo.letter[x] to always be afoo.x?  Because they aren't:

  afoo.A = 9
  afoo.letter['a']
1


What you are pointing out is that the assignment is not reversed . But 
that does make me thing of something I had not.


  afoo.letter['a'] = 345
  afoo.A
1

Thats kinda a bummer, whats a good way to make sure affo.A gets updated?


It's possible, and not too tough, but... why do you need it done that 
way?  Keeping redundant information seems like extra work with no advantage.


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


Re: how to cause a request for a missing class attribute cause its calculation

2010-05-18 Thread Ethan Furman

Vincent Davis wrote:
Lets say I have 
class foo(object):

def __init__(self, x, y):
self.x=x
self.y=y
def xplusy(self):
self.xy = x+y

 ^ this needs to be self.x + self.y


inst = foo(1,2)
inst.xy   # no value, but I what this to cause the calculation of inst.xy

I don't what to have self.xy calculated before it is called.


My current favorite method:

def __getattr__(self, name):
if name != 'xy':
raise AttributeError(%s not found % name)
self.xy = self.x + self.y
return self.xy


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


Re: Is this an ok thing to do in a class

2010-05-18 Thread Vincent Davis
On Tue, May 18, 2010 at 3:15 PM, Ethan Furman et...@stoneleaf.us wrote:

 Vincent Davis wrote:


 What you are pointing out is that the assignment is not reversed . But
 that does make me thing of something I had not.

   afoo.letter['a'] = 345
   afoo.A
 1

 Thats kinda a bummer, whats a good way to make sure afoo.A gets updated?


 It's possible, and not too tough, but... why do you need it done that way?
  Keeping redundant information seems like extra work with no advantage.

 Not sure I do, basicly I have a long list of values that could be
calculated from data. Some may take some time depending on the amount of
data. I don't what to calculate them all if not needed but I don't what the
user to need to know which are and which are not. But maybe @property is
what I need to be looking at, see my other post on the list.
Thanks
Vincent


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


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


another question about classes and subclassing

2010-05-18 Thread Alex Hall
Hi again all,
More about classes. I am still looking into my battleship game, and I
will have several different craft. All craft have common attribs
(position, alive, and so on) but each craft may be a surface ship,
submarine, or airplane. All three are craft, but a submarine can be
submerged or not, which does not apply to a surface ship or a plane,
while a plane can be airborne or not, which is not applicable to the
other two. Is there any advantage to creating a craft class:

class craft():
 #has attribs common to any and all craft
#end class

then doing something like:

class submarine(craft):
 #sub-specific attribs
#end class

How would I create a submarine, and then get at the craft-level
attribs? Come to think of it, how would I pass anything to the craft
constructor (position and alive, for example) when creating a new
submarine object? Am I even doing this right to make submarine a
subclass of craft? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


sound effects in python

2010-05-18 Thread Astan Chee

Hi,
I have a sound file (e.g. .wav; .mp3, etc) in python that I'd like to 
modify (e.g. change tempo, pitch, add echo, amplify, etc).
Any recommendation on how I can achieve this in python independent of 
platform?

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


Re: how to cause a request for a missing class attribute cause its calculation

2010-05-18 Thread Ethan Furman

Ethan Furman wrote:

Vincent Davis wrote:

Lets say I have class foo(object):
def __init__(self, x, y):
self.x=x
self.y=y
def xplusy(self):
self.xy = x+y

 ^ this needs to be self.x + self.y


inst = foo(1,2)
inst.xy   # no value, but I what this to cause the calculation of inst.xy

I don't what to have self.xy calculated before it is called.


My current favorite method:

def __getattr__(self, name):
if name != 'xy':
raise AttributeError(%s not found % name)
self.xy = self.x + self.y
return self.xy


~Ethan~


Chris' reply is more on-point, I think -- I was thinking of attributes 
that are only calculated once.  *sigh*


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


Re: sound effects in python

2010-05-18 Thread Vincent Davis
There was a talk at pycon about this. Sounded interecting but I don't know
much about it.
http://us.pycon.org/2010/conference/schedule/event/136/

Vincent

On Tue, May 18, 2010 at 4:05 PM, Astan Chee astan.c...@al.com.au wrote:

 Hi,
 I have a sound file (e.g. .wav; .mp3, etc) in python that I'd like to
 modify (e.g. change tempo, pitch, add echo, amplify, etc).
 Any recommendation on how I can achieve this in python independent of
 platform?
 Thanks
 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access to comp.lang.python

2010-05-18 Thread Tim Chase

On 05/15/2010 05:34 PM, cjw wrote:

It seems that messages are coming from a number of sources, such as
gmane and google groups.

The problem is that many messages seem to get unlinked from their threads.

I use Thunderbird 3.0.5 and wonder whether the problem lies with the
merge process, the server or my reader.


While others have told you about using gmane or other sources 
(direct email, etc), I haven't seen anything fly by regarding the 
unlinked from their threads portion of your question. 
Thunderbird 2.0 - 3.0 changed the default value for 
mail.strict_threading from False to True.  Pulling up the config 
editor (essentially the about:config, buried in the 
options-advanced stuff, I think; or perhaps I have the 
about:config plugin to do that) allows you to toggle this value 
back to True.  This setting controls whether threads are 
defined *only* by the mail header (strict=True), or whether TB 
also tries to guess based on the Subject header (strict=False).


Toggle it (and perhaps restart TB?) and see if that helps rectify 
the threading.  There are a lot of folks here on c.l.p that use 
broken newsreaders that don't correctly set news/threading headers.


-tkc



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


Re: sound effects in python

2010-05-18 Thread technocake
On 19 Mai, 00:05, Astan Chee astan.c...@al.com.au wrote:
 Hi,
 I have a sound file (e.g. .wav; .mp3, etc) in python that I'd like to
 modify (e.g. change tempo, pitch, add echo, amplify, etc).
 Any recommendation on how I can achieve this in python independent of
 platform?
 Thanks

You could have a look on PyAudio : http://people.csail.mit.edu/hubert/pyaudio/

I have not any experience with it, so I can only point you to it for
now. Hope you find it useful

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


Re: another question about classes and subclassing

2010-05-18 Thread Dave Angel

Alex Hall wrote:

Hi again all,
More about classes. I am still looking into my battleship game, and I
will have several different craft. All craft have common attribs
(position, alive, and so on) but each craft may be a surface ship,
submarine, or airplane. All three are craft, but a submarine can be
submerged or not, which does not apply to a surface ship or a plane,
while a plane can be airborne or not, which is not applicable to the
other two. Is there any advantage to creating a craft class:

class craft():
 #has attribs common to any and all craft
#end class

then doing something like:

class submarine(craft):
 #sub-specific attribs
#end class

How would I create a submarine, and then get at the craft-level
attribs? Come to think of it, how would I pass anything to the craft
constructor (position and alive, for example) when creating a new
submarine object? Am I even doing this right to make submarine a
subclass of craft? Thanks.

  
Inside the __init__() method of Submarine, simply call the __init__() 
method of Craft, with appropriate parameters.


As for getting at the attributes of the Craft parent class, from a 
Submarine object, you simply reference the attributes as always.  If 
they're not overridden in Submarine, they'll be searched for in Craft.



DaveA

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


Re: another question about classes and subclassing

2010-05-18 Thread Alex Hall
Okay, that makes sense. So by calling submarine(craft) I am bringing
in all of craft's attribs (subclassing)? Or does calling craft's
__init__ method do that instead? Is there an advantage to doing it
this way, rather than just making separate classes for everything,
except for my own sense of organization; speed, memory usage, less
coding? Thanks.

On 5/18/10, Dave Angel da...@ieee.org wrote:
 Alex Hall wrote:
 Hi again all,
 More about classes. I am still looking into my battleship game, and I
 will have several different craft. All craft have common attribs
 (position, alive, and so on) but each craft may be a surface ship,
 submarine, or airplane. All three are craft, but a submarine can be
 submerged or not, which does not apply to a surface ship or a plane,
 while a plane can be airborne or not, which is not applicable to the
 other two. Is there any advantage to creating a craft class:

 class craft():
  #has attribs common to any and all craft
 #end class

 then doing something like:

 class submarine(craft):
  #sub-specific attribs
 #end class

 How would I create a submarine, and then get at the craft-level
 attribs? Come to think of it, how would I pass anything to the craft
 constructor (position and alive, for example) when creating a new
 submarine object? Am I even doing this right to make submarine a
 subclass of craft? Thanks.


 Inside the __init__() method of Submarine, simply call the __init__()
 method of Craft, with appropriate parameters.

 As for getting at the attributes of the Craft parent class, from a
 Submarine object, you simply reference the attributes as always.  If
 they're not overridden in Submarine, they'll be searched for in Craft.


 DaveA




-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: upgrade python

2010-05-18 Thread Aahz
In article mailman.367.1274206734.32709.python-l...@python.org,
packet  fasteliteprogram...@gmail.com wrote:

Would it be safe to upgrade from python 2.6.4 to 2.6.5 without hurting 
the 2.6.4?

Define hurting.  Generally speaking, it's always safe to upgrade a
point release, but you should replace the previous version.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: another question about classes and subclassing

2010-05-18 Thread Dave Angel

Alex Hall wrote:

Okay, that makes sense. So by calling submarine(craft) I am bringing
in all of craft's attribs (subclassing)? Or does calling craft's
__init__ method do that instead? Is there an advantage to doing it
this way, rather than just making separate classes for everything,
except for my own sense of organization; speed, memory usage, less
coding? Thanks.

snip

You put your response at the wrong end of the message.  It should 
*follow* whatever you're quoting.  So in your case, I'm forced to delete 
everything just to make the order correct.


You don't call Submarine(Craft), as it's not a function.  That's a class 
definition.  You instantiate a Submarine by something like:


sub = Submarine(arg1, arg2, arg3)

And those three arguments are then passed to the __init__() method of 
Submarine.  It may choose to call the __init__() method of Craft, in the 
method.


There are lots of advantages of using inheritance.  First, any common 
code only has to be entered once, so you'll only have to fix it once 
when you find mistakes, or decide to redesign.  Second, it's easier to 
read - very important.  It may take less memory, but probably not.  And 
it's not likely to have any speed impact.


Craft instances don't have any instance data attributes if nobody 
assigns them.  And that's normally the job of __init__().  So naturally, 
you need to call it from the Submarine class.


Incidentally, convention is to capitalize class names.

DaveA

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


Pointers on packaging python programs for installation on multiple platforms?

2010-05-18 Thread gobnat
Hi all

I am trying to release my first python program.  I would like to be able to 
create a download which will automatically do stuff like add menu items (eg for 
KDE, GNOME and Windows).  Is there anywhere which explains how to do this? 

Thanks in advance


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


Re: another question about classes and subclassing

2010-05-18 Thread Alex Hall
On 5/18/10, Dave Angel da...@ieee.org wrote:
 Alex Hall wrote:
 Okay, that makes sense. So by calling submarine(craft) I am bringing
 in all of craft's attribs (subclassing)? Or does calling craft's
 __init__ method do that instead? Is there an advantage to doing it
 this way, rather than just making separate classes for everything,
 except for my own sense of organization; speed, memory usage, less
 coding? Thanks.

 snip

 You put your response at the wrong end of the message.  It should
 *follow* whatever you're quoting.  So in your case, I'm forced to delete
 everything just to make the order correct.
Sorry, top-posting is a habit on some other lists I am on, and
sometimes it follows me to lists where in-line posting is the way to
do it.

 You don't call Submarine(Craft), as it's not a function.  That's a class
 definition. You instantiate a Submarine by something like:

 sub = Submarine(arg1, arg2, arg3)

 And those three arguments are then passed to the __init__() method of
 Submarine.  It may choose to call the __init__() method of Craft, in the
 method.
So that is the only way of making submarine inherit craft, by calling
craft's __init__ inside submarine's __init__. Okay, I think I get it.

 There are lots of advantages of using inheritance.  First, any common
 code only has to be entered once, so you'll only have to fix it once
 when you find mistakes, or decide to redesign.
Very true.
 Second, it's easier to
 read - very important.  It may take less memory, but probably not.  And
 it's not likely to have any speed impact.

 Craft instances don't have any instance data attributes if nobody
 assigns them.  And that's normally the job of __init__().  So naturally,
 you need to call it from the Submarine class.
Right, I think I have it now... At least I hope I do!

 Incidentally, convention is to capitalize class names.
Yes, I had planned on doing that in my project, but I got caught up in
just making it work and forgot to do so. Thanks for the reminder.

 DaveA




-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access to comp.lang.python

2010-05-18 Thread Terry Reedy

On 5/18/2010 7:27 PM, Tim Chase wrote:

On 05/15/2010 05:34 PM, cjw wrote:

It seems that messages are coming from a number of sources, such as
gmane and google groups.

The problem is that many messages seem to get unlinked from their
threads.

I use Thunderbird 3.0.5 and wonder whether the problem lies with the
merge process, the server or my reader.


While others have told you about using gmane or other sources (direct
email, etc), I haven't seen anything fly by regarding the unlinked from
their threads portion of your question. Thunderbird 2.0 - 3.0 changed
the default value for mail.strict_threading from False to True. Pulling
up the config editor (essentially the about:config, buried in the
options-advanced stuff, I think; or perhaps I have the about:config
plugin to do that) allows you to toggle this value back to True. This
setting controls whether threads are defined *only* by the mail header
(strict=True), or whether TB also tries to guess based on the Subject
header (strict=False).


I solved the problem for me, well enough, by sorting threads by subject 
instead of 'Date' (actually, time) so that disconnect threads sort 
together anyway.


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


Re: recall function definition from shell

2010-05-18 Thread Terry Reedy

On 5/18/2010 2:55 PM, superpollo wrote:


yes python does not, but maybe the *shell* does, or so i thought. i just
wanted to dump the code for the function in a file, after i tested in
the shell...


On Windows, you can tell the shell (command window) how many lines to 
remember. One can sensibly make this a lot higher on a gigabyte machine 
than back in the 640K days. No idea about other systems.




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


Re: upgrade python

2010-05-18 Thread Terry Reedy

On 5/18/2010 9:47 PM, Aahz wrote:

In articlemailman.367.1274206734.32709.python-l...@python.org,
packetfasteliteprogram...@gmail.com  wrote:


Would it be safe to upgrade from python 2.6.4 to 2.6.5 without hurting
the 2.6.4?


Define hurting.  Generally speaking, it's always safe to upgrade a
point release, but you should replace the previous version.


The default action on windows is replace. I keep the previous installer 
around with the current one fora while in case a bugfix release has a 
problem and I need to revert.


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


Re: Picking a license

2010-05-18 Thread Ben Finney
This thread is already off-topic and too long. I'm conflicted about my
role in that; I have endeavoured only to address falsehoods that IMO
were not otherwise being addressed.

So I'll try to keep this brief.

Ethan Furman et...@stoneleaf.us writes:

 This doesn't make sense to me, but I'm willing to learn -- how do you
 do this in practice? Are you really selling the software

Perhaps in private email we can discuss what you mean by “really selling
the software”; it's too off-topic here. By my understanding of that
term, yes, I am selling software.

 or rather selling things like setup, support, new code (or time to
 code), etc?

All of the above, depending on the project.

-- 
 \   “If you don't know what your program is supposed to do, you'd |
  `\ better not start writing it.” —Edsger W. Dijkstra |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help need to write a python spell checker

2010-05-18 Thread Nigel Rowe
On Fri, 14 May 2010 18:19, harry k wrote in comp.lang.python
mailman.205.1273907726.32709.python-l...@python.org:

 Write a spell checking tool that will identify all misspelled word in
a text file using a provided dictionary.
 
snip/
  
 Extend the spell-checking tool so that the program will also print out
a list of possible correct spellings for the words.
 

I'm happy to do you homework for you, cost is us$1000 per hour.  Email
to your professor automatically on receipt.

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


Re: help need to write a python spell checker

2010-05-18 Thread Steven D'Aprano
On Wed, 19 May 2010 13:01:10 +1000, Nigel Rowe wrote:

 I'm happy to do you homework for you, cost is us$1000 per hour.  Email
 to your professor automatically on receipt.

I'll do it for $700 an hour!



-- 
Steven

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


Classes and threading

2010-05-18 Thread Adam W.
I thought I knew how classes worked, but this code sample is making my
second guess myself:

import threading

class nThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self,args):
print self.name
print self.args

pants = nThread(args=('fruit'),name='charlie')
pants.start()

Traceback (most recent call last):
  File C:\Users\Adam\Desktop\PyTiVo\task_master.py, line 13, in
module
pants = nThread(args=('fruit'),name='charlie')
TypeError: __init__() got an unexpected keyword argument 'args'

Shouldn't __init__ still handle these (as per
http://docs.python.org/library/threading.html#thread-objects ), even
if its subclassed?  I thought this was the whole idea of inheritance
and overdriving.


And sort of related, why does this crash IDLE GUI but not the command
line?:

import threading

class nThread(threading.Thread):

def run(self):
print 2+2

pants = nThread()
pants.start()


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


question on logging module

2010-05-18 Thread frank zhu
Hi,
From the python 2.6.4 tutorial, refer to
http://docs.python.org/release/2.6.4/tutorial/stdlib2.html#logging

The above example doesn't work for me.
Here is script log

#

o...@oem-desktop ~ $ python -V
Python 2.6.4
o...@oem-desktop ~ $ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type help, copyright, credits or license for more information.
 import logging
 logging.debug('debug information')
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'module' object has no attribute 'debug'



I am current using python2.6.4.

Can anyone point out what's problem?
Thanks,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Classes and threading

2010-05-18 Thread Erik Max Francis

Adam W. wrote:

I thought I knew how classes worked, but this code sample is making my
second guess myself:

import threading

class nThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self,args):
print self.name
print self.args

pants = nThread(args=('fruit'),name='charlie')
pants.start()

Traceback (most recent call last):
  File C:\Users\Adam\Desktop\PyTiVo\task_master.py, line 13, in
module
pants = nThread(args=('fruit'),name='charlie')
TypeError: __init__() got an unexpected keyword argument 'args'

Shouldn't __init__ still handle these (as per
http://docs.python.org/library/threading.html#thread-objects ), even
if its subclassed?  I thought this was the whole idea of inheritance
and overdriving.


You've overridden the __init__ method to _not_ take any arguments, and 
explicitly call its parent constructor not passing anything.  So it 
shouldn't be a wonder that it won't accept any arguments.


If you don't intend to override the constructor in the parent class, 
simply don't define it.


--
Erik Max Francis  m...@alcyone.com  http://www.alcyone.com/max/
 San Jose, CA, USA  37 18 N 121 57 W  AIM/Y!M/Skype erikmaxfrancis
  I like young girls. Their stories are shorter.
   -- Thomas McGuane
--
http://mail.python.org/mailman/listinfo/python-list


Re: help need to write a python spell checker

2010-05-18 Thread Patrick Maupin
On May 14, 3:19 am, harry k hkiri...@yahoo.com.au wrote:

 Write a spell checking tool that will identify all misspelled word in a text 
 file using a provided dictionary.

Well, this has been educational.  Both my daughters just finished
their final exams last week, so I was confused about seeing the
homework assignment.  Then I saw the email address.  Although it makes
perfect sense, I never really thought much about the possibility that
the school year would be upside down down under...

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


  1   2   3   >