[no subject]

2012-03-10 Thread Sam Sam
How to change the color of source browser in DrPython?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please don't feed the trolls

2021-03-09 Thread Sam

On 3/8/21 3:35 PM, Chris Angelico wrote:

On Tue, Mar 9, 2021 at 8:31 AM D'Arcy Cain  wrote:


On 2021-03-06 4:24 p.m., Terry Reedy wrote:

Trolling, among other things, is fishing with a moving line, especially
with a revolving lure, as from a moving boat.  A troll, among other
things, is that method or the lure used.


You are confusing "troll" with "trawl"



https://en.wikipedia.org/wiki/Trolling_(fishing)

ChrisA




If you teach a man to fish

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


Re: memory consumption

2021-04-01 Thread Sam

On 3/29/21 5:12 AM, Alexey wrote:

Hello everyone!
I'm experiencing problems with memory consumption.

I have a class which is doing ETL job. What`s happening inside:
  - fetching existing objects from DB via SQLAchemy
  - iterate over raw data
  - create new/update existing objects
  - commit changes

Before processing data I create internal cache(dictionary) and store all 
existing objects in it.
Every 1 items I do bulk insert and flush. At the end I run commit command.

Problem. Before executing, my interpreter process weighs ~100Mb, after first 
run memory increases up to 500Mb
and after second run it weighs 1Gb. If I will continue to run this class, 
memory wont increase, so I think
it's not a memory leak, but rather Python wont release allocated memory back to 
OS. Maybe I'm wrong.

What I tried after executing:
  - gc.collect()
  - created snapshots with tracemalloc and searched for some garbage, diff =
smapshot_before_run - smapshot_after_run
  - searched for links with "objgraph" library to internal cache(dictionary
containing elements from DB)
  - cleared the cache(dictionary)
  - db.session.expire_all()

This class is a periodic celery task. So when each worker executes this class 
at least two times,
all celery workers need 1Gb of RAM. Before celery there was a cron script and 
this class was executed via API call
and the problem was the same. So no matter how I run, interpreter consumes 1Gb 
of RAM after two runs.

I see few solutions to this problem
1. Execute this class in separate process. But I had few errors when the same 
SQLAlchemy connection being shared
between different processes.
2. Restart celery worker after executing this task by throwing exception.
3. Use separate queue for such tasks, but then worker will stay idle most of 
the time.
All this is looks like a crutch. Do I have any other options ?

I'm using:
Python - 3.6.13
Celery - 4.1.0
Flask-RESTful - 0.3.6
Flask-SQLAlchemy - 2.3.2

Thanks in advance!



I had the (mis)pleasure of dealing with a multi-terabyte postgresql 
instance many years ago and figuring out why random scripts were eating 
up system memory became quite common.


All of our "ETL" scripts were either written in Perl, Java, or Python 
but the results were always the same, if a process grew to using 1gb of 
memory (as your case), then it never "released" it back to the OS. What 
this basically means is that your script at one time did in fact 
use/need 1GB of memory. That becomes the "high watermark" and in most 
cases usage will stay at that level. And if you think about it, it makes 
sense. Your python program went through the trouble of requesting memory 
space from the OS, it makes no sense for it to give it back to the OS as 
if it needed 1GB in the past, it will probably need 1GB in the future so 
you will just waste time with syscalls. Even the glibc docs state 
calling free() does not necessarily mean that the OS will allocate the 
"freed" memory back to the global memory space.


There are basically two things you can try. First, try working in 
smaller batch sizes. 10,000 is a lot, try 100. Second, as you hinted, 
try moving the work to a separate process. The simple way to do this 
would be to move away from modules that use threads and instead use 
something that creates child processes with fork().


Regards,



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


Re: Python garbage collection: not releasing memory to OS!

2016-04-15 Thread Sam

On 04/15/2016 05:25 AM, cshin...@gmail.com wrote:

I have written an application with flask and uses celery for a long running 
task. While load testing I noticed that the celery tasks are not releasing 
memory even after completing the task. So I googled and found this group 
discussion..

https://groups.google.com/forum/#!topic/celery-users/jVc3I3kPtlw

In that discussion it says, thats how python works.

Also the article at 
https://hbfs.wordpress.com/2013/01/08/python-memory-management-part-ii/ says

"But from the OS's perspective, your program's size is the total (maximum) memory 
allocated to Python. Since Python returns memory to the OS on the heap (that allocates 
other objects than small objects) only on Windows, if you run on Linux, you can only see 
the total memory used by your program increase."

And I use Linux. So I wrote the below script to verify it.

 import gc
 def memory_usage_psutil():
 # return the memory usage in MB
 import resource
 print 'Memory usage: %s (MB)' % 
(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000.0)

 def fileopen(fname):
 memory_usage_psutil()# 10 MB
 f = open(fname)
 memory_usage_psutil()# 10 MB
 content = f.read()
 memory_usage_psutil()# 14 MB

 def fun(fname):
 memory_usage_psutil() # 10 MB
 fileopen(fname)
 gc.collect()
 memory_usage_psutil() # 14 MB

 import sys
 from time import sleep
 if __name__ == '__main__':
 fun(sys.argv[1])
 for _ in range(60):
 gc.collect()
 memory_usage_psutil()#14 MB ...
 sleep(1)

The input was a 4MB file. Even after returning from the 'fileopen' function the 
4MB memory was not released. I checked htop output while the loop was running, 
the resident memory stays at 14MB. So unless the process is stopped the memory 
stays with it.

So if the celery worker is not killed after its task is finished it is going to 
keep the memory for itself. I know I can use **max_tasks_per_child** config 
value to kill the process and spawn a new one. **Is there any other way to 
return the memory to OS from a python process?.**




With situations like this, I normally just fork and do the mem intensive 
work in the child and then kill it off when done. Might be  able to use 
a thread instead of a fork. But not sure how well all that would work 
with celery.


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


Java JMS and python

2020-04-13 Thread Sam

Hi,

We are not a java shop and we are trying to interface with an API that 
is "JMS only". We asked if it supported activeMQ or STOMP and they 
replied that it is Sun JMS only. So what does that mean if we want to 
communicate with it from python or similar? Curious if 
anyone else has been down this path...


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


Re: Java JMS and python

2020-04-13 Thread Sam

On 4/13/20 9:51 PM, Julio Oña wrote:

Hi

There is a tool for that (I didn't use it):
https://docs.spring.io/spring-python/1.2.x/sphinx/html/jms.html

Hope it works for you.
Julio

El lun., 13 de abr. de 2020 a la(s) 22:44, Chris Angelico
(ros...@gmail.com) escribió:


On Tue, Apr 14, 2020 at 11:20 AM Sam  wrote:


Hi,

We are not a java shop and we are trying to interface with an API that
is "JMS only". We asked if it supported activeMQ or STOMP and they
replied that it is Sun JMS only. So what does that mean if we want to
  communicate with it from python or similar? Curious if
anyone else has been down this path...



I don't know what JMS is, but have you tried searching PyPI for it?

Worst case, most of these sorts of protocols (if I'm reading you
correctly) are built on top of things that Python *does* understand
(TCP/IP, or HTTP, or somesuch), so you should be able to reimplement
the protocol yourself. But try PyPI first.

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





I had high hopes for the spring for python project.. but looks like it 
is dead? Most docs for it point to dates of 2009 and all the source 
links point to dead websites.


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


Re: Ram memory not freed after executing python script on ubuntu system

2020-05-28 Thread Sam

On 5/28/20 12:49 AM, Rahul Gupta wrote:


I am having a Ubuntu system which has 125 Gb of RAM. I executed few python 
scripts on that system. Those scripts uses numpy arrays and pandas. Now 
execution was over but still 50 gb of RAM and 2 Gb cache and 8.4 Gb of swap is 
occupied. At this moment nothing is running on the system. I have googled it. 
Most of th result shows that python garbage collector is poor in performance. I 
want this memory to be cleaned and re claim. One of the easiest way is to 
restart the system but i dont want to restart i want a way to do this when the 
system is up and running. Kindly tell me how to do this. Thanks




Give us the output of:
cat /proc/meminfo
and
ps aux

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


Re: Threading, real or simulated?

2005-09-22 Thread Sam

Antoon Pardon writes:


Assuming you mean threading.Thread, this is a native thread.  It is not a 
simulation.  Something else is going wrong.


Then I must have something locked.  Here's what I do:


Yes you have locked the GIL. Take a look at the following
URL: http://docs.python.org/api/threads.html, hope it helps.


Yes, thank you.  That was it.

Since I was creating threads, and messing with them, in pure Python with 
threading.Thread, I never had an opportunity to read this part of the API 
spec.





pgphmv1znQGt9.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

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

2005-09-30 Thread Sam

Reinhold Birkenfeld writes:


Hi,

after Guido's pronouncement yesterday, in one of the next versions of Python
there will be a conditional expression with the following syntax:

X if C else Y

which is the same as today's

(Y, X)[bool(C)]


What's wrong with "C ? X:Y"?

Aside from ":" being overloaded?



pgpZksJ3aZt0b.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

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

2005-09-30 Thread Sam

Jaime Wyant writes:


On 9/30/05, Sam <[EMAIL PROTECTED]> wrote:

Reinhold Birkenfeld writes:

> Hi,
>
> after Guido's pronouncement yesterday, in one of the next versions of Python
> there will be a conditional expression with the following syntax:
>
> X if C else Y
>
> which is the same as today's
>
> (Y, X)[bool(C)]

What's wrong with "C ? X:Y"?

Aside from ":" being overloaded?



First thing that comes to my mind is that it is more C-ish (read
cryptic) than pythonic (read elegant and understandable).


And "foo if bar" is Perl-ish; yet, even Perl has the ? : operators.




pgp2YIfNenxUE.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

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

2005-10-01 Thread Sam

Leif K-Brooks writes:


Sam wrote:

And "foo if bar" is Perl-ish; yet, even Perl has the ? : operators.


What _isn't_ Perl-ish?


BASIC?




pgp7WNg5zZz7a.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Setting optimum gtkhtml2 widget size.

2005-10-02 Thread Sam
I'm putting gtkhtml2.View() inside a gtk.ScrolledWindow, which goes into a 
gtk.Dialog.vbox.


How do I obtain gtkhtml2.View's preferred height, and set the dialog's 
height accordingly, given a specific width?


I can do a gtk.Dialog.set_default_size() up front, specifying the width and 
height large enough for everything, then create all the widgets, and realize 
them.


But then, even after I realize everything I can't get any useful metrics 
from gtkhtml2.View().  None of the usual suspects -- get_size_request, 
get_allocation -- give anything useful.


I also tried not using a ScrolledWindow, but adding gtkhtml2 as 
gtk.Dialog.vbox's child.


pgp8liVmGWclS.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Python eats gator.

2005-10-05 Thread Sam

http://www.wnbc.com/family/5060215/detail.html

I know there's an on-topic joke in here somewhere, but I'm having some
problem finding it, at the moment.

You may take a crack at it, if you'd like…



pgpWkRit76A0o.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: C/API Clarification

2005-10-07 Thread Sam

Jeremy Moles writes:


in the world I got the idea from! According to the docs, METH_VARARGS is
(PyObject*, PyObject*)?


Right.


My prototype shouldn't even compile... but it


Why wouldn't it compile?


2. No where in the docs does it show how to "correctly" create an
instance of your custom PyTypeObject in C (rather than in the
interpreter). I'm using:


That's what tp_alloc is for.  Then you call tp_init to initialize it.

But, your tp_new handler should already invoke tp_alloc, so it's cleaner to 
call tp_new, followed by tp_init.



3. I'm not able to return the "self" argument (useful, for instance,
when you want to chain a group of method calls) without screwing things
up really, really bad. For example:

PyObject* somefunc(cstruct* self, PyObject* args, PyObject* kargs) {
self->pointerToData->doSomeStuff();

return (PyObject*)(self);
}

...returns "something"; it has the methods you would expect, but trying
to use the object when it gets back to the interpreter is pretty much
undefined behavior. :) It's seen as a "" instance in the
interpreter, even though a dir() shows it still has the methods you
would expect.


You need to increment the reference count of the object, in this case.



pgpU4yWTepvmr.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Daisy Daisy, give me your answer do

2005-10-08 Thread Sam

Xah Lee writes:


Dear Michael Goettsche,

why don't you lead the pack to be on-topic for a change, huh?


Why don't you:

1.  Learn how to properly format messages for posting to Usenet, so that 
your scribblings don't read like stream-of-consciousness babbling

(see http://en.wikipedia.org/wiki/Top-posting).

2.  Explain why such an important and famous ubergeek like yourself (judging 
by your web site) has to beg others to write code for him.


3.  Make sure the door handle doesn't hit your ass on the way out.




pgpPbnLZqTCxN.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Wanted: Python module allowing direct access to raw sectors ofharddrives (MFT, boot sector, etc.) in MS Windows

2005-10-10 Thread sam
The following site contains my routines to access information from the
Microsoft SCSIPASSTHROUGH layer under windows. These routines allow you
to access the storage devices mounted under windows using SCSI
commands. The dll that I provide will work with Python 2.3

http://starship.python.net/crew/samschul/

Sam Schulenburg

Claudio Grondi wrote:
> Thank you Jeff very much for your quick reply.
> It saved me really much time of digging in the wrong direction.
>
> <[EMAIL PROTECTED]> wrote in
> news:<[EMAIL PROTECTED]>...
> >> I took the advice from this web page:
> >> http://support.microsoft.com/kb/q100027/
> Ok, I had found this page myself during Googling, but I have missed just
> to try to use the described way of addressing physical devices with file
> opening in Python.
> It works as expected with harddrives so you are right that you are getting
> the MBR with the proposed code.
>
> After some not always happy end adventures with Python
> scripting I am impressed by the power of the concept behind
> the language once again.
>
> Claudio
>
> >>(I don't know how this extends to floppies, and the 9x family of OSes
> isn't
> >>listed in "applies to", so this may not help your case)
> >>Here, I open "physical drive 0" and see that the magic number indicates a
> valid
> >>boot record. I believe it is the MBR.
> >>>>> f = open('.\\PhysicalDrive0', 'rb')
> >>>>> f.read(512)[-2:]
> >>'U\xaa' # that is, hex 55 AA
> >>I don't know much about low-level filesystem or partition details--I got
> the
> >>tidbit about the 55 AA magic number from
> >>http://www-uxsup.csx.cam.ac.uk/pub/doc/suse/sles9/adminguide-sles9/ch08.ht
> ml
> >>Jeff
> >><[EMAIL PROTECTED]> schrieb im Newsbeitrag
> news:[EMAIL PROTECTED]

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


Re: Wanted: Python module allowing direct access to raw sectors ofharddrives (MFT, boot sector, etc.) in MS Windows

2005-10-11 Thread sam
The main use of my SCSI routines,is that by using the SCSIPASSTHROUGH
layer under Windows gives the user absolute control of the storage
device. For example copying data from and IDE drive to a SCSI drive
becomes transparent using SCSI commands. I.e Logical block 0 remains
consistant. I had an PHD clam that using fopen(),and fread(),along with
fwrite()  with an offset of 0 would always get you sector zero,head
zero on a drive. I was able to prove that this was not the case. When
using the SCSIPASSTHROUGH layer LBA 0 will always return the first user
accessable sector. Using Python open() behaves the same as the C
functions,thus you would have the same problem.

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


modpython, apache and windows

2005-01-04 Thread Sam
Hi All,
I am interested in learning python since I am hearing more and more 
about python for use in web development

I am starting out on python, with knowledge of PHP some perl
my current hurdle is setting up either apache 1 or 2 with python 2.3.3 I 
have installed modpython fine

which informed me that I need to make some configuration changes to 
httpd.conf

I have not had it working yet, searches on the web give conflicting 
suggestions and so far has confused me

some forums mention spyce and serving .spy files
so far I  one explanation worked in that a .py file was parsed but I had 
to set the name of the actual file within apache.conf
this seems strange

thanks in advance >> SS
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.298 / Virus Database: 265.6.7 - Release Date: 30/12/2004
--
http://mail.python.org/mailman/listinfo/python-list


Powerful CGI libraries for Python?

2005-01-09 Thread sam
Hi,
I m looking for a CGI libraries just  like perl's CGI.pm for Python.
From google, I found quite a few of CGI libraries already written for 
python. But I haven't had experience to try any of them in Python.

Can anyone share your Python CGI experience with me? Which library is 
better in terms of functionality and stability?

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


Excel module for Python

2005-01-11 Thread sam
Hi group,
I m wondering which Excel module is good to be used by Python?
Thanks
Sam
--
http://mail.python.org/mailman/listinfo/python-list


Re: Excel module for Python

2005-01-12 Thread sam
Simon Brunning wrote:
On Wed, 12 Jan 2005 15:18:09 +0800, sam <[EMAIL PROTECTED]> wrote:
I m wondering which Excel module is good to be used by Python?

If you are on Windows, and you have Excel, then the Python for Windows
extensions[1] are all you need to drive Excel via COM. O'Reilly's
"Python Programming on Win32" covers COM scripting extensively - and
by good fortune, driving Excel is the example they use, and the COM
scripting chapter is on-line[2].
You'll also need to know the objects and methods that Excel exposes.
These are documented on Microsoft's web site[3], or in the Excel VBA
help, which is an optional part of they Office installation.
No, I don't use MS windows. I need to generate Excel file by printing 
data to it, just like Perl module Spreadsheet::WriteExcel.

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


compile python to binary

2005-01-23 Thread sam
Hi,
I have seen some software written in python and delivered as binary form.
How does these binary code get generated by python compiler?
Thanks
Sam.
--
http://mail.python.org/mailman/listinfo/python-list


Re: compile python to binary

2005-01-23 Thread sam
Fredrik Lundh wrote:
Daniel Bickett wrote:

I believe Sam was talking about "frozen" python scripts using tools
such as py2exe:

oh, you mean that "python compiler" didn't mean "the python compiler".
here are links to some more tools, btw:
http://effbot.org/zone/python-compile.htm
Thanks for the link. It is what I exactly looking for.
Thanks
Sam
 


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


Re: compile python to binary

2005-01-23 Thread sam
Peter Hansen wrote:
Daniel Bickett wrote:
Fredrik Lundh wrote:
oh, you mean that "python compiler" didn't mean "the python compiler".
[snip]

I simply inferred that he was using the wrong terminology, being that
he said "binary" twice ;-)

While I suspect you've guessed correctly at what the OP
meant, one should also consider that the word "binary"
can be quite ambiguous in the hands of a newbie.
After all, source code is stored in binary too...
Sorry for the vagues terms. I meant compile a python script into a 
binary program.

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


python module in webmin

2005-01-26 Thread sam
Hi,
Had anyone written any python module for webmin?
Since  webmin is written in perl, but I want to write a python 
app/module used by webmin. If you know the detail of writing a python 
module for use in perl webmin, please drop me some guideline.

Perhaps It is better off to find/write a python version of webmin first.
Thanks
Sam.
--
http://mail.python.org/mailman/listinfo/python-list


Threading, real or simulated?

2005-09-21 Thread Sam
I'm using Python 2.3.5 with pygtk 2.4.1, and I'm using the second threading 
approach from pygtk's FAQ 20.6 - invoking "gtk.gdk.threads_init()", and 
wrapping all gtk/gdk function calls with 
gtk.threads_enter()/gtk.threads_leave()


I start a thread, via thread.Threading.start().  The thread then calls a 
particularly time consuming C function, from an extension module.  I find 
that when the thread is running the C code, the GUI hangs even though I'm 
not inside the threads_enter/threads_leave territory.


It looks like thread.Threading() only simulates threading, by having the 
python interpreter multiplex between running threads.  Is real threading 
possible, so that I do something time-consuming in the thread, without 
hanging the GUI?





pgp2z4y14Omjn.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Threading, real or simulated?

2005-09-21 Thread Sam

Jp Calderone writes:


On Wed, 21 Sep 2005 18:23:33 -0500, Sam <[EMAIL PROTECTED]> wrote:
I'm using Python 2.3.5 with pygtk 2.4.1, and I'm using the second threading 
approach from pygtk's FAQ 20.6 - invoking "gtk.gdk.threads_init()", and 
wrapping all gtk/gdk function calls with 
gtk.threads_enter()/gtk.threads_leave()


I start a thread, via thread.Threading.start().  The thread then calls a 
particularly time consuming C function, from an extension module.  I find 
that when the thread is running the C code, the GUI hangs even though I'm 
not inside the threads_enter/threads_leave territory.




  Does the extension module release the GIL?  It sounds like it does not.  Of 
course, there are a dozen other mistakes that could be made which would have 
roughly this symptom.  It's difficult to say which is the problem without 
actually seeing any code.


What's the GIL?.  The extension module is invoked outside of 
threads_enter/threads_leave().


It looks like thread.Threading() only simulates threading, by having the 
python interpreter multiplex between running threads.  Is real threading 
possible, so that I do something time-consuming in the thread, without 
hanging the GUI?




Assuming you mean threading.Thread, this is a native thread.  It is not a 
simulation.  Something else is going wrong.


Then I must have something locked.  Here's what I do:

   gtk.gdk.threads_init()
   mainwindow=MainWindow()
   gtk.threads_enter()
   gtk.main()
   gtk.threads_leave()


The code in MainWindow.__init__() does this:

   self.__window=gtk.Window(gtk.WINDOW_TOPLEVEL)
   self.__window.set_default_size(600, 600)

   [ some more initialization ]

   self.__window.show_all()
   self.__window.connect("delete-event", self.delete_event)
   self.__window.connect("destroy", self.destroy)

   t=self.initializationThread()
   t.packageLayout=packageLayout
   t.start()

Here's the definition of my initializationThread class:

   class initializationThread(threading.Thread):
   def run(self):
   gtk.threads_enter()
   busy_cursor=gtk.gdk.Cursor(gtk.gdk.WATCH)
   self.packageLayout.window.set_cursor(busy_cursor)
   gtk.threads_leave()


I do get a busy cursor at this point, so I know that this thread is running. 
initializationThread.run() continues, as follows:


   try:
   sysrep=lpm.getSystemRepository()
   pkgs=sysrep.getPackages()
   pkgs.sort()
   for i in pkgs:
   icon=sysrep.getManifest(i).header("Icon")
   gtk.threads_enter()
   try:
   if self.packageLayout.window == None:
   break  # Someone was impatient
   self.packageLayout.addPackage(i, icon)
   finally:
   gtk.threads_leave()


lpm.getSystemRepository() instantiates an object of an extension-defined 
type.  It's getPackages() method returns a list of objects that are also of 
an extension-defined type, which I then iterate over.  Each iteration 
invokes the getManifest() method of an extension-defined type.


All the stuff between gtk.threads_enter() and gtk.threads_leave() runs pure 
python code, and should be nearly instantaneous.  Furthermore, gtk functions 
that end up being invoked in the addPackage() method, provide some GUI 
feedback.  Each addPackage() iteration adds a new widget in the main window.


Occasionally, there's a noticeable delay, before a new widget appears, 
because there's a lot on getManifest()'s plate.  I get no response from any 
GUI activity, during the delay.  getManifest() gets invoked outside the 
threads_enter/threads_leave lock, but the GUI is still hanging when that 
happens.





pgp1CNTdr48aH.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

create/access dynamic growth list

2005-03-17 Thread sam
Hi,
I have a configuration file need to be processed (read/write) by python.
Currently I the following method can only read and store data that 
python read a line from a configuraiton file:
 def _parse (self):
# parse message
m = self.FWShow_Command.match (conf_data)
if (m == None):
raise FW_Command.Error ("corrupt macro definition")

# store generic data
macro = {}
macro["key"] = m.group (1)
macro["value"] = m.group (2)
return (conf_data, macro)
Since there are unknown number of lines in a configuration file, I want 
to store the array of "macro" in a list.
How can I do that in Python?

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


syntax incorrect with regex

2005-03-18 Thread sam
Hi,
What is the correct syntax of declaring a regex syntax in Python 2.3?
I got the following error:
# python2.3 test.py
  File "test.py", line 10
macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOS)
^
SyntaxError: invalid syntax
Thanks
sam
--
http://mail.python.org/mailman/listinfo/python-list


Re: create/access dynamic growth list

2005-03-18 Thread sam
Larry Bates wrote:
sam wrote:
Hi,
I have a configuration file need to be processed (read/write) by python.
Currently I the following method can only read and store data that
python read a line from a configuraiton file:
def _parse (self):
   # parse message
   m = self.FWShow_Command.match (conf_data)
   if (m == None):
   raise FW_Command.Error ("corrupt macro definition")
   # store generic data
   macro = {}
   macro["key"] = m.group (1)
   macro["value"] = m.group (2)
   return (conf_data, macro)
Since there are unknown number of lines in a configuration file, I want
to store the array of "macro" in a list.
How can I do that in Python?
Thanks
Sam.
Pretty sketchy description, but I'll take a shot.
fp=open(conf_data, 'r')
macro_lines=fp.readlines()
fp.close()
After this macro_lines will be a list with one line per element
such that macro_list[0] is the first line, macro_list[1] the
second, etc.
Thanks for the suggestion.
Since each line of the configuration file need to be parsed into "key" 
and "value" pairs, these pair of tokens need to be stored in another 
list. Can I use the following operation to store these pair of tokens?
eg.
Assumed macro_hash["key"]="some key"
	macro_hash["value"]="some value"
then build a list that contains a list of macro_hash:
   macro_list.append(macro)
when treverse the macro_list, it would be similar to perl:
   foreach macro (in macro_list)
	key = macro["key"]
	value = macro["value"]

Sam.

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


inline comparison

2005-03-19 Thread sam
Hi,
I got the the following syntax error in comparison:
  File "/usr/local/work/myparser.py", line 85
if ( (m=self.macro_parser.match (d)) != None ):
   ^
SyntaxError: invalid syntax
How can I get around wtih this? I don't want to break down this 
comparison in two steps.

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


what is \s+ and \S+ means in re.compile?

2005-03-20 Thread sam
Hi,
I was confused by \s+ and \S+ in python.
The second one (\S+) is stand for matching all alphabets except for 
digit and space? How about the first one?

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


Re: inline comparison

2005-03-20 Thread sam
Tim Roberts wrote:
sam <[EMAIL PROTECTED]> wrote:

Hi,
I got the the following syntax error in comparison:
 File "/usr/local/work/myparser.py", line 85
   if ( (m=self.macro_parser.match (d)) != None ):
  ^
SyntaxError: invalid syntax
How can I get around wtih this? I don't want to break down this 
comparison in two steps.

Sorry, you have to.  Assignment statements are not expressions in Python.  

m = self.macro_parser.match(d)
if m:
xxx
This is very bad to me, I will need to write some cumbersome syntax as 
follow:
   for d in self.data:
m = self.macro_parser.match (d)) != None ):
if (m == None):
   m_nat = self.a_parser.match (d)
   if (m_a == None):
  m_rdr = self.b_parser.match (d)
  if (m_b == None):
  m_c = self.c_parser.match (d)
  if (m_c == None):
 m_d = self.d_parser.match (d)
 if (m_d == None):
m_e = self.e_parser.match (d)
if (m_e == None):
 .


You know the outer parentheses are not necessary, right?
--
http://mail.python.org/mailman/listinfo/python-list


Avaliable free modules

2004-12-16 Thread sam
Hi group,
Is there any site like cpan.org for python?
Thanks
Sam
--
http://mail.python.org/mailman/listinfo/python-list


Re: inline comparison

2005-03-21 Thread sam
Diez B. Roggisch wrote:

If you really need that sort of dependent matching, there are better ways to
accomplish that in python:
for m, name in [self.macro_parser, self.a_parser, self.b_parser, ...]:
mo = m.match(data)
if mo:
   break
Hi, this method looks more elegant.
However I got the following error:
for m, name in [self.macro_parser]
   ^
SyntaxError: invalid syntax
What is the valid syntax with this usage?
Thanks
Sam

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


How to get Mac address of ethernet port?

2014-01-11 Thread Sam
I would like to use python to retrieve the mac address of the ethernet port. 
Can this be done? Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get Mac address of ethernet port?

2014-01-11 Thread Sam
On Sunday, January 12, 2014 12:34:35 AM UTC+8, Michael Torrie wrote:
> On 01/11/2014 07:35 AM, Andriy Kornatskyy wrote:
> 
> 
> On Linux you could access the /sys/devices/virtual/net/
> 
> file in the sysfs filesystem.  I'm sure there are other ways.
> 

Thank you to everyone for the helpful answers. I am using Linux in this case. I 
think this is the direction I am looking for. Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Is it better to import python modules inside function or at the top? What are the pros and cons?

2014-01-11 Thread Sam
I have python modules which are used only in specific functions and the 
functions are not called all the time. Is it better to import the function 
inside the function only or is it a better practice to always import all 
modules at the top of the script? If I import the module inside the function, 
will it cause a big performance hit because of the import module action that 
gets to be called every time the function is called?

What are the pros and cons of each approach?
-- 
https://mail.python.org/mailman/listinfo/python-list


Building and accessing an array of dictionaries

2014-01-16 Thread Sam
I would like to build an array of dictionaries. Most of the dictionary example 
on the net are for single dictionary.

dict = {'a':'a','b':'b','c':'c'}
dict2 = {'a':'a','b':'b','c':'c'}
dict3 = {'a':'a','b':'b','c':'c'}

arr = (dict,dict2,dict3)

What is the syntax to access the value of dict3->'a'?

Thank you.

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


Is it possible to protect python source code by compiling it to .pyc or .pyo?

2014-01-16 Thread Sam
I would like to protect my python source code. It need not be foolproof as long 
as it adds inconvenience to pirates.

Is it possible to protect python source code by compiling it to .pyc or .pyo? 
Does .pyo offer better protection?

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


Compiling main script into .pyc

2014-01-16 Thread Sam
One thing I observe about python byte-code compiling is that the main script 
does not gets compiled into .pyc. Only imported modules are compiled into .pyc. 

May I know how can I compile the main script into .pyc? It is to inconvenience 
potential copy-cats.
-- 
https://mail.python.org/mailman/listinfo/python-list


Process datafeed in one MySql table and output to another MySql table

2014-01-16 Thread Sam
I have a datafeed which is constantly sent to a MySql table. The table grows 
constantly as the data feeds in. I would like to write a python script which 
process the data in this table and output the processed data to another table 
in another MySql database in real-time.

Which are the python libraries which are suitable for this purpose? Are there 
any useful sample code or project on the web that I can use as reference? Thank 
you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Process datafeed in one MySql table and output to another MySql table

2014-01-17 Thread Sam
On Friday, January 17, 2014 10:07:58 AM UTC+8, Denis McMahon wrote:
> On Thu, 16 Jan 2014 17:03:24 -0800, Sam wrote:
> 
> 
> 
> > I have a datafeed which is constantly sent to a MySql table ...
> 
> 
> 
> > Which are the python libraries which are suitable for this purpose? Are
> 
> > there any useful sample code or project on the web that I can use as
> 
> > reference?
> 
> 
> 
> Did you search for mysql on the python docs website, or perhaps try 
> 
> googling "python mysql"?
> 

I did. There were documentation but I was hoping to have more sample code. 
Preferably a similar project which I can use as reference.

> 
> 
> -- 
> 
> Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


python and matlab

2014-02-06 Thread Sam
is it able to utilize functions written in Python in Matlab?
-- 
https://mail.python.org/mailman/listinfo/python-list


Why use _mysql module and not use MySQLdb directly?

2014-02-08 Thread Sam
I am writing my first python script to access MySQL database. With reference to 
http://mysql-python.sourceforge.net/MySQLdb.html#connection-objects

Why is it advisable to use _mysql and not MySQLdb module directly?
-- 
https://mail.python.org/mailman/listinfo/python-list


What is the recommended python module for SQL database access?

2014-02-08 Thread Sam
Is MySQLdb the recommended python module for SQL database access? Are there 
other modules? What I want in a module is to be able to write readable and 
maintainable code.
-- 
https://mail.python.org/mailman/listinfo/python-list


What does """ means in python?

2014-02-08 Thread Sam
For string, one uses "" to represent string. Below is a code fragment that uses 
""" instead.

cursor.execute("""SELECT name, phone_number 
  FROM coworkers 
  WHERE name=%s 
  AND clue > %s 
  LIMIT 5""",
   (name, clue_threshold))

What does """ means in python?
-- 
https://mail.python.org/mailman/listinfo/python-list


What are the kinds of software that are not advisable to be developed using Python?

2014-02-08 Thread Sam
I got to know about Python a few months ago and today, I want to develop only 
using Python because of its code readability. This is not a healthy bias. To 
play my own devil's advocate, I have a question. What are the kinds of software 
that are not advisable to be developed using Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python boilerplate

2016-03-21 Thread Sam

On 03/19/2016 07:43 AM, Fernando Felix do Nascimento Junior wrote:

A simple boilerplate for those who don't know the structure of a project. 
https://goo.gl/lJRvS6

## Features

* Build and distribute with setuptools
* Check code style with flake8
* Make and run tests with pytest
* Run tests on every Python version with tox
* Code coverage with coverage.py

## Structure

Structure of the project in tree format.

├── CONTRIBUTING.md
├── LICENSE
├── Makefile
├── MANIFEST.in
├── module_name.py
├── README.md
├── requirements
│   ├── dev.txt
│   └── prod.txt
├── requirements.txt
├── setup.cfg
├── setup.py
├── tests.py
└── tox.ini

Fernando Felix




There is this too: https://pypi.python.org/pypi/python_boilerplate_template


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


Best practices to overcome python's dynamic data type nature

2014-02-14 Thread Sam
Dynamic data type has pros and cons. It is easier to program but also easier to 
create bugs. What are the best practices to reduce bugs caused by Python's 
dynamic data-type characteristic? Can the experienced Python programmers here 
advise?

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


Can one use Python to learn and even apply Functional Programming?

2014-02-15 Thread Sam
I would like to learn and try out functional programming (FP). I love Python 
and would like to use it to try FP. Some have advised me to use Haskell instead 
because Python is not a good language for FP. I am sort of confused at the 
moment. Is Python a dysfunctional programming language to apply FP? Can the 
more experienced Python users advise?
-- 
https://mail.python.org/mailman/listinfo/python-list


Can global variable be passed into Python function?

2014-02-20 Thread Sam
I need to pass a global variable into a python function. However, the global 
variable does not seem to be assigned after the function ends. Is it because 
parameters are not passed by reference? How can I get function parameters to be 
passed by reference in Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Can tuples be replaced with lists all the time?

2014-02-22 Thread Sam
My understanding of Python tuples is that they are like immutable lists. If 
this is the cause, why can't we replace tuples with lists all the time (just 
don't reassign the lists)? Correct me if I am wrong.
-- 
https://mail.python.org/mailman/listinfo/python-list


Print statement not printing as it suppose to

2013-09-20 Thread Sam
hi everybody i am just starting to learn python, i was writing a simple i/o 
program but my print statement is acting weird. here is my code i want to know 
why it prints this way. thank you


car=int(input("Lamborghini tune-up:"))

rent=int(input('\nManhatan apartment: '))

gifts=int(input('\nRandom Gifts: '))

total=car+rent+gifts

print("\nThe total amount required is ", total )


OUTPUT

Lamborghini tune-up:1000

Manhatan apartment: 2300

Random Gifts: 234
('\nThe total amount required is ', 3534)



===> the problem is obviously on the last print statement that is supposed to 
print the outut
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: access to preallocated block of memory?

2005-12-15 Thread sam
I had a simular situation when I was writing Python routines to access
the the storage (SCSIPASSTHROUGH) layer provided by Windows XP. My
solution was to develope an extention in C that allocated all storage
buffers within the extension. Then I added access extensions to
controll reading and writing to and from these buffers. I would guess
that you can write a vxworks extension that provides this linkage.
Bengt Richter wrote:
> On 14 Dec 2005 14:30:34 -0800, "Greg Copeland" <[EMAIL PROTECTED]> wrote:
>
> >I am running python on VxWorks.  In the course of operation, a vxworks
> >tasks writes to a reserved area of memory.  I need access to this chunk
> >of memory from within python.  Initially I thought I could simply
> >access it as a string but a string would reallocate and copy this chunk
> >of memory; which is not something I can have as it would waste a huge
> >amount of memory.  We're talking about something like 40MB on a device
> >with limited RAM.  I have been looking at array.  It looks promising.
> >What's the best route to go here?  Ideally, I would like to simply pass
> >in the address of the reserved block and a length, and have the memory
> >accessible.
> >
> >Is there some existing python object/facility I can use or will I need
> >to create a custom module?  Any tips, hints, or pointers would
> >certainly be appreciated!
>
> What have you gathered from people who have gone before? googling python 
> vxworks
> gives about 50k hits ;-)
>
> Your post does not have enough info about your environment, but for
> the sake of eliciting same, suppose you had a custom extension module
> written in C that would give you the access to the "reserved area of memory"
> that you want. So e.g. from the point of view of your python program, it looks
> like a module you can import, e.g.,
>
> import vxreservedmem
>
> Ok, how does the module know where the "reserved area" is? Would you link
> the C to some vx library interface to establish location and size? Or?
> Is there already a python interface to provide some access?
> Can there be more than one instance, so the module should be able to
> give you multiple objects that you can use to access different areas?
>
> Once you have an access-providing object, what kind of access do you require?
> What is represented within the "memory area" besides an array of bytes? Do the
> bytes represent C structs and primitive types? Are there access locks that
> determine when it's safe to touch the bytes? A single lock for the whole area,
> or individual locks for structs/subregions within the whole? Do you just need
> read access or do you want to store info? How would you like to select
> chunks of info? Just slices of byte arrays, or are there meaningful arrays
> of numbers -- integer, floats, etc. or bit fields etc?
>
> You could define a pure python vxresrvedmem module that just simulates the 
> real
> thing, to test ideas -- and to communicate more clearly to us what the 
> problem is.
>
> What modules/libraries do you have to give you access now from python to the 
> vxworks
> environment? A file system? /dev/magic_stuff? or /proc/magic_stuff or ?
> 
> 
> Regards,
> Bengt Richter

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


UpDate For SCSIPython Storage device test library

2005-12-28 Thread sam
I have updated my page at http://starship.python.net/crew/samschul/
These tools allow for the user to issue low level SCSI commands via the
windows SCSIPASSTHROUGH interface layer. These routines will work from
IDLE, Pythonwin,and Python.exe.

The changes include the following:
1) Deleted documentation references to ASPY interface as it is not used
very much anymore.
2) Compiled SCSIPy.dll for Python 2.3 and Python 2.4 see
SCSITOOLS23USBUpdate.zip,and SCSITOOLS24USBUpdate.zip
4) Made many changes to documentation

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


Re: UpDate For SCSIPython Storage device test library

2005-12-30 Thread sam
Just a added note,that these routines will access any storage drive
that is mounted under Windows. The Scsi Pass Through layer maps all
Pcmcia,IDE,andSCSI drives to use SCSI commands. This allows a user to
access all these interfaces with a common command set.

Sam Schulenburg

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


Re: UpDate For SCSIPython Storage device test library

2006-01-03 Thread sam
I found a bug in the GetLastError() call I was making after all calls
to DeviceIOControl() when accessing the devices mounted by Windows.
This has been corrected and posted to
http://starship.python.net/crew/samschul/  These changes have been made
to SCSITOOLS23USBVer1.4.zip, and SCSITOOLS24USBV1.4.zip

Sam Schulenburg

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


Re: Microsoft IronPython?

2006-01-07 Thread sam
After downloading and trying out Ironpython, I have the following
comments:
1) I like the idea of Python under .net
2) I like the support for both Microsoft math lib,and Python's math lib
Will Microsoft maintain the compatability between standard python with
the addition of their libs?

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


Building Pywin32 source code?

2006-01-08 Thread sam
Has anyone been able to access the source code for Pywin32 at
sourceforge? I have been able to use TortouseCVS to access other CVS
projects,but with the Pywin32 cvs site, I can not log in.

Sam Schulenburg

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


Re: Building Pywin32 source code?

2006-01-09 Thread sam
Trent:
Thanks for the reply. I tried again today and everthing worked. I did
find a type in my CVSROOT string,and corrected it. Thanks for the
examples posted in the included link.

Sam Schulenburg

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


matplotlib, wxPanel inside a wxPanel

2006-08-12 Thread Sam
Hello,

I'm currently creating a GUI, which consists of a main frame that
contains a menu bar,a toolbar and an empty panel, let's call it
main_panel.
Ideally, I'd like the following functionality: upon choosing an item
from the menu bar, a particular graph will be displayed inside
main_panel.

Now I've taken a look at the 'embedding_in_wx' example files that come
with matplotlib. Using this example, I can place a graph in a panel
(let's call it graph_panel), and display this in a frame. I can also
get NavigationToolbar2 to work completely.

On the other hand, when i create graph_panel and put this inside of
main_panel, NavigationToolbar2 does not work. The graph and toolbar are
both displayed, but none of the buttons on the toolbar do anything.

I'm beginning to think that what i'm trying to do isn't actually
possible, and that i'll need to put it in a frame instead, which is a
pity.

Can anyone please advise if what i'm trying to do is possible and if
so, provide a small example? I'm running windows XP, python 2.4,
wxpython 2.6.

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


Re: matplotlib, wxPanel inside a wxPanel

2006-08-12 Thread Sam
Hi Daniel,

Thanks very much for your quick response! You're right, it was a case
of the cut-and-paste blues, and me not really knowing what each part of
the code in the examples was actually doing.
A couple of things caught me out: first of all, i wasn't calling
SetSizer and Fit on the right panels...
Secondly, I stuffed up when trying to give graph_panel a parent of
main_panel. It turns out I was actually never doing this, so the
toolbar would appear, but none of the buttons would work.

Thanks again for your comments, they were very helpful,
Cheers
Sam

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


"wxmsw26uh_vc.dll not found" when using wxAgg backend

2006-08-15 Thread Sam
Hello,

I've installed matplotlib recently because I want to add graphing
functionality to a GUI that i'm making. I decided to try using the
wxAgg backend instead of plain old wx because:
a) I hear it's quicker, and
b) when i use the wx backend, the axis labels don't seem to work
properly - i can't change their font, and the axis label always
overwrites my tickbox labels.

So i'm not too concerned about these wx problems anymore because i'm
changing to wxAgg.

Here's the problem i'd like help with.
- i import the wxAgg backends, Figurecanvas, etc.
- i run the file
- the following error box pops up: "This application has failed to
start because wxmsw26uh_vc.dll was not found. Reinstalling the
application may fix this problem."

This problem occurs even when I run the matplotlib example files that
you can download from the matplotlib homepage.
I have tried reinstalling, and that has not rectified the problem.

I googled for wxmsw26uh_vc.dll and found a small number of posts. The
following post:
https://svn.enthought.com/enthought/ticket/774
suggests that it will be "fixed in 1.0.0.rc1" which was supposedly
released a few weeks ago.
I didn't really follow the discussion of why this error is occurring, i
just want to find out how to fix it!

I'm running a windows XP machine with: python 2.4, matplotlib 87.4 and
wxPython ansi-2.6.3.3

Any help would be much appreciated
Cheers
Samantha

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


error handling in user input: is this natural or just laborious

2006-10-06 Thread sam
hi all,

i'm starting to put together a program to simulate the performance of
an investment portfolio in a monte carlo manner doing x thousand
iterations and extracting data from the results.

i'm still in the early stages, and am trying to code something simple
and interactive to get the percentages of the portfolio in the five
different investment categories. i thought i'd get in with the error
handling early so if someone types in something wrong (like a word), or
the numbers don't add up to 100%, the error would be caught immediately
and the user sent back to the start of the loop. granting that there
may be better ways of doing this, if i decide that i do want to do it
like this (i.e. a single error requires all data to be re-entered, not
unreasonable for only five items), is this a good way of doing it or a
confusing way of doing it from the perspective of readability and
maintenance:

while True:

cash, bond, blue, tech, dev = 0,0,0,0,0
check=False

try:
cash=input('Please enter a cash percentage for the portfolio: ')
except NameError:
print 'That is not a number. Please start again and remember to 
enter
integers.'
else:
try:
bond=input('Please enter a bond portfolio for the 
portfolio: ')

except NameError:
print 'That is not a number. Please start again and 
remember to
enter integers.'
else:
try:
blue=input('Please enter a blue-chip percentage 
for the portfolio:
')
except NameError:
print 'That is not a number. Please start again 
and remember to
enter integers.'
else:
try:
tech=input('Please enter a tech stocks 
percentage for the
portfolio: ')
except NameError:
print 'That is not a number. Please 
start again and remember to
enter integers.'
else:
try:
dev=input('Please enter a 
developing countries index for the
portfolio: ')
check=True
except NameError:
print 'That is not a number. 
Please start again and remember to
enter integers.'

if cash+bond+blue+tech+dev==100:
break
if cash+bond+blue+tech+dev!=100 and check!= False:
print 'Those numbers do not sum to 100. Please start again.'



i know it's a bit verbose, but it was the nested try clauses i was
really wondering about. is the code immediate legible to experienced
python users? or does it look like gibberish at first?

just hoped for some fresh eyes on it.

thanks,

sam

PS making check=True just saves the code from printing 'those numbers
don't sum to 100' if they haven't all been entered, which looks kind of
silly.

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


Re: error handling in user input: is this natural or just laborious

2006-10-06 Thread sam
you're right, of course. it occurred to me that, even if it were
manageable for a few items, it would quickly become absurd as the
number of items grew. this:

def get_pct():
while True:
pct_list=[['cash', 0], ['bond', 0], ['blue', 0], ['tech', 0], 
['dev',
0]]
total=0
for i in range(len(pct_list)):
pct_list[i][1]=input('Please enter the percentage value 
for %s: '
%pct_list[i][0])
total+=pct_list[i][1]
if total == 100:
return pct_list
break
else:
print "You've messed up, do it again..."

is much better, and easily maintainable by adding to the assignment for
pct_list. still leaves me with checking for strings though, in case
someone types 'donut' at the prompt...

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


Re: error handling in user input: is this natural or just laborious

2006-10-06 Thread sam
this does what i want, though i don't like the inner while loop having
to be there


def get_pct():
while True:
pct_list=[['cash', 0], ['bond', 0], ['blue', 0], ['tech', 0], 
['dev',
0]]
total=0
for i in range(len(pct_list)):
while True:
pct_list[i][1]=raw_input('Please enter the 
percentage value for %s:
' %pct_list[i][0])
if pct_list[i][1].isdigit() == False:
print "You've messed up, do it again..."
else:
total+=int(pct_list[i][1])
break
if total == 100:
return pct_list
break
else:
print "You've messed up, do it again..."


gosh, a lot of work to get some input. i must be missing something,
though this is a lot better than what i had before...

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


Re: error handling in user input: is this natural or just laborious

2006-10-07 Thread sam
a huge amount to think about there. special thanks to james for taking
the time to make such   detailed responses. the problem is that even
though nested loops and the like place a heavy analytical burden on the
programmer (i.e. me) as he tries to remember what does what,
conceptualizing a program as a collection of classes and functions tied
together with a minimal amount of code brings to bear what is, at the
moment, an even greater burden.

my gut feeling is that, over time (as james said was true in his own
case), and with practice, the relative weights of these two burdens
change so that the procedural approach becomes easier to adopt, and its
benefits of readability and maintainability easier to enjoy. fingers
crossed...

i will continue coding the monte carlo machine until it does what i
want in more or less clumsy fashion, and might put it up here if it
feels like it would be of interest.

thanks again,

sam

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


print time comparison: IDLE versus terminal on ultra 20

2006-10-08 Thread sam
hi all,

i continue to footle around on my spanking new ultra 20 (1.8GHz /
Opteron Model 144), gradually trying to get to grips with python and
unix both.

the slow print time in IDLE had already struck me as rather odd.
running programs with heavy print requirements from the terminal was a
major discovery though, printing being so fast as to make everything
appear at once except in the case of literally thousands of items to be
printed.

test case:

import time

time1 = time.time()
for i in range(100):
print 'go get \'em, son!'
time2 = time.time()

print time2-time1


in IDLE:
4.433 seconds

in terminal:
0.001 seconds

a difference of between 3 and 4 orders of magnitude is rather striking.
anyone know what's going on here? is it a python, a unix thing, or
something else?

sam

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


Re: print time comparison: IDLE versus terminal on ultra 20

2006-10-08 Thread sam
i was actually experimenting on windows on my own pc before the
workstation arrived, and IDLE printed a lot faster on windows than in
solaris for me too.

i would indeed complain to sun if i had ever got the impression that
anyone over there ever knew what was going on...   : )

> but on the other hand, IDLE runs your sample script in less than 0.5
> seconds on my cheap Windows box.  complain to Sun ;-)
> 
> 

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


Re: print time comparison: IDLE versus terminal on ultra 20

2006-10-09 Thread sam
i forgot to mention that i'm running a version of python 2.3 (think
it's 2.3.5), as that's what was installed and i'm not hooked up to the
internet with the ultra 20 yet. that may account for some of the
difference.

sam

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


program written to model population evolving over time

2006-11-04 Thread sam
dear all,

i've just finished a program which sets up an initial population
consisting of four different phenotypes, allows them to evolve over
time and graphs the output at the end, displaying what is in effect the
evolutionary steady state for the system.

i'm no authority on evolutionary game theory (to put it mildly), but
there is a certain amount of interesting emergent behaviour if you put
the initial parameters in in a certain manner.

excuse my ignorance, but is there a site where people post this kind of
stuff? i figured someone might be interested in playing with it,
tweaking it a bit, changing the parameters. i've only been programming
a couple of months, so i'm sure more experienced programmers could
whack into shape if they were interested. or not...

it's about 500 lines, including white space and comments, probably
about 400 lines of pretty unconcise code in all. thought i'd try and
contribute something for once instead of just asking questions.

sam

PS it does actually work, in case you're wondering.  :-)

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


accessing fortran modules from python

2006-11-16 Thread sam
hello all,

i am currently in the process of planning a piece of software to model
polymerisation kinetics, and intend to use python for all the
high-level stuff. the number-crunching is something i would prefer to
do in fortran (which i have never used, but will learn), but i have no
experience of accessing non-python code from python. i am also fairly
new to programming period, and am therefore tackling a fairly serious
issue reletive to my experience.

how easy is it to get fortran modules running from python? if c is
easier to use in this respect, i could go in that direction instead.

i realize there is a lot of material on this subject already available,
but i am finding it difficult to make sense of, it's like trying to
take a drink from a fire hose.

any advice would be gratefully received. i will almost certainly be
coding this on windows, for what it's worth.

thank you,

sam

PS if numpy is adequate for this, i would be quite happy to use it. i
got the impression it was more for matrix algebra. i will be
programming a monte carlo simulation, which will need to perform a lot
(a lot!) of simple operations over and over...

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


Re: accessing fortran modules from python

2006-11-16 Thread sam
thanks guys,

i'll follow this up more in a couple of weeks when i know what i need
to do better.

sam

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


Re: How do you practice Python?

2006-06-02 Thread sam
Years ago I developed a Hard Disk Drive diagnostic program "SCSIPython"
while working for  a disk drive company. When I left that company,and
realized that these routines would never be used by the company, I
released it as Open Source. Since then I have maintained this code, and
enhanced it with the various versions of Python that have been released
after V1.5.
I find that with each update my code becomes more robust,with added
features. Also As I moved from company to company I made certain that
they knew that this code was Open Source,and only proprietary methods
will be excluded, when I signed the standard intellectual property
forms.

Sam Schulenburg


Jarek Zgoda wrote:
> [EMAIL PROTECTED] napisa³(a):
>
> >>In our field, we don't always get to program in the language we'd like
> >>to program. So... how do you practice Python in this case?
> >
> > Write code.  Lots of it.  Work on a project at home, contribute to
> > something open source, use it to write support scripts at work,
> > whatever.  Figure out a way to write code.
>
> I second that. I moved from Python to J2EE in my job, but I didn't stop
> writing Python code for my spare-time projects. Now, when tight schedule
> made my project's manager to shift paradigm from buzz to productivity, I
> am happy I can write programs in Python again. On AS/400, but still
> better than Java... :D
> 
> -- 
> Jarek Zgoda
> http://jpa.berlios.de/

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


Re: Seg fault in python extension module

2006-06-02 Thread sam
I recommend that you also replace the NULL after the METH_VARARGS with
a valid documentations string such as:

static PyMethodDef modglMethods[] =
   {
 { (char *)"glVertex4f", _wrap_glVertex4f, METH_VARARGS, "My
Doc String"},
 { NULL, NULL, 0, NULL }

  };

Sam Schulenburg

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


Re: Seg fault in python extension module

2006-06-02 Thread sam
Sorry, From MethodObject.h the 4th parameter is usually documented as
having a NULL, but is intended to be used for a documentation string
that will be available to the user under the various GUI IDE's such as
IDLE or PyWin32. I just wanted to point that out..

struct PyMethodDef {
const char  *ml_name;   /* The name of the built-in function/method */
PyCFunction  ml_meth;   /* The C function that implements it */
int  ml_flags;  /* Combination of METH_xxx flags, which mostly
   describe the args expected by the C func */
const char  *ml_doc;/* The __doc__ attribute, or NULL */
};

Sam Schulenburg

John Machin wrote:
> On 3/06/2006 1:38 PM, sam wrote:
> > I recommend that you also replace the NULL after the METH_VARARGS with
> > a valid documentations string such as:
> >
> > static PyMethodDef modglMethods[] =
> >{
> >  { (char *)"glVertex4f", _wrap_glVertex4f, METH_VARARGS, "My
> > Doc String"},
> >  { NULL, NULL, 0, NULL }
> >
> >   };
> >
>
> Lack of one is unlikely to have anything to do with the OP's segfault.
>
> |>>> repr(modgl.glVertex4f.__doc__)
> 'None'
> |>>>
>
> As to style, etiquette, and good citizenship in module extension
> writing, it might be better to give him some references, rather than
> mention just one point.
> 
> Cheers,
> John

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


Re: carshing the interpreter in two lines

2006-06-03 Thread sam
tomer:

It is my opinion that you would loose performance if the Python
interpreter had the additional task of verifying byte code. It might be
more appropriate to have a preprocessor that did the verifying as it
compiled the byte code.

Sam Schulenburg

gangesmaster wrote:
> the following (random) code crashes my interpreter
> (python 2.4.3/winxp):
>
> from types import CodeType as code
> exec code(0, 5, 8, 0, "hello moshe", (), (), (), "", "", 0, "")
>
> i would expect the interpreter to do some verifying, at least for
> sanity (valid opcodes, correct stack size, etc.) before executing
> artbitrary code... after all, it was the BDFL who said """I'm not
> saying it's uncrashable. I'm saying that if you crash it, it's a
> bug unless proven harebrained."""
> 
> 
> -tomer

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


Re: carshing the interpreter in two lines

2006-06-03 Thread sam
Mel:
Wow that book brings back memories. I scanned my copy to review the
subject covered, and came to the conclusion that mind reading
algorithms are the answer.

Sam Schulenburg

Mel Wilson wrote:
> sam wrote:
> > tomer:
> >
> > It is my opinion that you would loose performance if the Python
> > interpreter had the additional task of verifying byte code. It might be
> > more appropriate to have a preprocessor that did the verifying as it
> > compiled the byte code.
>
> Possibly.  A good book on the topic is Douglas Hofstadter's
> _Goedel, Escher, Bach: an Eternal Golden Braid_.
>
> Particularly starting from the chapter "Contracrostipunctus".
>
>  Cheers,Mel.
>
>
>
> > Sam Schulenburg
> >
> > gangesmaster wrote:
> >> the following (random) code crashes my interpreter
> >> (python 2.4.3/winxp):
> >>
> >> from types import CodeType as code
> >> exec code(0, 5, 8, 0, "hello moshe", (), (), (), "", "", 0, "")
> >>
> >> i would expect the interpreter to do some verifying, at least for
> >> sanity (valid opcodes, correct stack size, etc.) before executing
> >> artbitrary code... after all, it was the BDFL who said """I'm not
> >> saying it's uncrashable. I'm saying that if you crash it, it's a
> >> bug unless proven harebrained."""
> >>
> >>
> >> -tomer
> >

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


Re: Very nice python IDE (windows only)

2006-06-07 Thread sam
Very interesting, I have downloaded it,and I like what I see.

ago wrote:
> I have just discovered Python Scripter by Kiriakos Vlahos and it was a
> pleasant surprise. I thought that it deserved to be signalled. It is
> slim and fairly fast, with embedded graphical debugger, class browser,
> file browser... If you are into graphical IDEs you are probably going
> to enjoy it. Windows only unfortunately.
> 
> http://mmm-experts.com/Products.aspx?ProductId=4

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


Re: Most elegant way to generate 3-char sequence

2006-06-11 Thread sam
I have found that the more elegant the code is, the harder it is for me
to understand what it is trying to accomplish. It is my opinion that
"Keep It Simple" wins over elegance. When I have had the urge to get
elegant, I make sure I comment the elegance so my less elegant
co-workers can figure out what I was trying to accomplish.

Sam Schulenburg


James Stroud wrote:
> Fredrik Lundh wrote:
> > James Stroud wrote:
> >
> >> See the actual question:
> >>
> >>  >How would you construct a generator to acheive this?
> >
> >
> > if you don't think the context provided by the subject line and the
> > sentence before the question is important, how come you're so sure what
> > "this" refers to ?
> >
> > 
> >
>
> I'm getting the feeling that "correct" answers have nothing to do with
> correctness (i.e. working code) but on some vague notion of "elegance".
> Please point me to the page where code elegance is precisely defined so
> that I may construct my answers appropriately. And yes, I am too lazy to
> google "code elegance".
>
> James
>
> --
> James Stroud
> UCLA-DOE Institute for Genomics and Proteomics
> Box 951570
> Los Angeles, CA 90095
> 
> http://www.jamesstroud.com/

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


Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-16 Thread sam
I have been using the latest VC.net to compile my SCSIPython extension
dll for Python 2.3, 2.4, and  2.5  without any problems. I just have to
make shure that I link with the correct Python.lib

Sam Schulenburg

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


"list index out of range" error

2006-09-20 Thread sam
hey everybody, this is my first time posting here. i'm pretty new to
python and programming in general (as you'll soon work out for
yourselves...)

i'm trying to code a version of a selection sort and the heart of the
code is as follows (no_lines is simply the number of items to be
sorted, read out of an input file):

for j in range(0, no_lines):

k = 0
while k < no_lines:
sorted_check = 0
if list_initial[k] < list_initial[k+1]:
temp_str = list_initial[k]
elif list_initial[k] == list_initial[k+1]:
temp_str = list_initial[k]
elif list_initial[k] > list_initial[k+1]:
temp_str = list_initial[k+1]
sorted_check = 1
k += 1

list_initial.remove(temp_str)
list_final.append(temp_str)
no_lines -= 1

if sorted_check == 0:
break

problem is, i keep getting a "list index out of range" error. i've had
this problem before in different contexts with lists in loops.

i thought i had it cracked when it occurred to me that i needed to
decrement no_lines to take into account that list_initial was shrinking
as i deleted sorted items, but i still got the same error. it's
probably something trivial, but i can't seem to get round it by using
while loops, and i had the same problem with cmp(), hence the explicit
comparison above, which still doesn't work. can anyone help a beginner
out with this?

many thanks in advance,

sam lynas

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


Re: "list index out of range" error

2006-09-20 Thread sam
actually, that little bit of code i wrote is obscenely wrong anyway, so
please don't bother analyzing the flow.

any insight into the "list index out of range" error would still be
welcome, though.

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


Re: "list index out of range" error

2006-09-20 Thread sam
yes, yes, of course, thank you. not sure what i thought i was doing
there.
i'll see if i can get it running now...

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


Re: "list index out of range" error

2006-09-20 Thread sam
for what it's worth. and it is approx. five times quicker than the
bubblesort i wrote to begin with on a 286-word highly unordered list,
so i wasn't wasting my time after all...

__
import time

file_input = open('wordlist.txt', 'r')

list_initial = []

no_lines = 0

for line in file_input:
list_initial.append(line)
no_lines += 1

no_lines_2 = no_lines

print list_initial

file_input.close()

raw_input('press enter to sort: ')

list_final = []
temp_str = ""

time1 = time.clock()

for j in range(no_lines_2):

temp_str = 'zz'
for k in range(no_lines):
if temp_str > list_initial[k]:
temp_str = list_initial[k]
list_initial.remove(temp_str)
list_final.append(temp_str)
no_lines -= 1

time2 = time.clock()
final_time = time2 - time1
print list_final
print
print 'number of seconds for sort list: ', final_time
print
print 'number of words in list: ', no_lines_2
___

thanks again for your help. that sorted out something that had really
been bugging me.

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


Re: "list index out of range" error

2006-09-20 Thread sam
gabriel,

> Now that your main problem is gone, just a few comments:
> - python lists know their length, so you don't need explicit no_lines
> and no_lines_2
> - list_initial.remove(temp_str) is fairly slow - it has to *scan* the
> list to locate temp_str. Just keep its index instead, and use del
> list_initial[index]

i will try rewriting it in that manner and comparing the times. i have
no feel so far for the relative speeds of different ways of doing
things, but i can see the importance of it.

> - as a general sorting routine, that 'zzz' does not look very
> good, try to avoid it.

yes, it's hideous even to a novice. however, i need to go to bed now,
and if i hadn't got this to work before bed, i'd never get to sleep!
i'll have to mull it over and come up with something more elegant.


ben,

i used to work for a company where we exchanged a lot of e-mails, and
the titles were always 're: your e-mail', or 'project stuff', or 'file
for client' or suchlike. made it kind of difficult to find anything.
figured a similar principle might apply here... ; )

thanks again all,

sam

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


returning None instead of value: how to fix?

2006-09-22 Thread sam
i am starting to experiment with recursion, and decided to write a
fairly trivial little program which took a float as input, then called
a function to halve it recursively until it was less than 1:


import recursive_halve_module

raw_value = raw_input('please enter the number you would like to halve:
')
value = float(raw_value)

final_value = recursive_halve_module.recursive_halve(value)

print final_value

raw_input('hit enter to close: ')
_

def recursive_halve(value):

if value < 1:
print value
return value
else:
value = value/2
print value
if value < 1:
return value
else:
recursive_halve(value)
__

it works fine apart from printing 'None' instead of 'final_value' at
the end. however, if you enter a value that is already less than 1, it
prints 'final_value' (i.e. that very same number) just fine.

now, it looks to me like only 'value' can be returned: either right at
the beginning (for values less than 1) or when you eventually get down
to below 1 after x function calls. but clearly that's not the case. i
understand that 'None' is returned by default by functions in Python.
my question is: how am i slipping into that default despite seemingly
(to me at least) avoiding it through explicitly returning something
else?

thanks in advance,

sam

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


Re: returning None instead of value: how to fix?

2006-09-22 Thread sam
> Missing a return on the last line is likely your immediate problem.

thanks to everyone for pointing this out. obviously, i had not
understood what was actually involved in a recursive call. i have
corrected it as suggested and it works fine now.

> You have more subtle problems, though.  First, you have needlessly
> reduplicated value<1 test--the first thing recursive_halve does is to
> check whether value<1, so there's no need to check whether value<1
> before calling it.

yes, i could see this was nasty. i figured i'd go back and try and
streamline it afterwards. i wrote an insertion sort yesterday and i had
to cheat by putting two items into a new list to begin with, and only
then enter the nested loops to do the rest of it. i seem to be fighting
my way into a process to get a foothold, and only then trying to finish
it smoothly/elegantly. hopefully this will ease up with time and
practice.

> Second, you have redundant branching logic.  Look at your first else
> statement.  It does nothing; the else doesn't affect whether the stuff
> inside it gets executed or not; it's redundant.  It's better style to
> not to have such redundancy (either by omitting the else, or having a
> single return point).

if i understand this correctly, you mean that the function will
terminate if it returns 'value'  at the beginning, so the else: is
implicit in the fact that the interpreter has even got that far. i take
your point about trying to abbreviate what is, in effect, verbiage.

thanks again for all the answers. it boggles the mind that one can have
access to this almost immediate help at no charge.

sam

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


python interpreter on solaris 10

2006-09-25 Thread sam
dear all,

having spent the last couple of weeks getting to grips with python on
windows, i am in the position of trying to make the transition to my
newly arrived ultra 20.

however, although there are plenty of files with idle somewhere in the
title, idle.py (which i assume is the interpreter) will not open, as
there is 'no installed viewer.' surely sun have not installed python
only for it to unusable? i may well be completely off base here, as
using unix is still very much a mystery to me.

i have tried /usr/sfw/lib/python at the command prompt. it worked
yesterday, but having now moved and restored the python2.3 file to its
original position, i find the same command prompt failing to work. have
i messed it up by moving it around?

my workstation remains a shiny box which does naught but hum
malevolently. is there hope?

thank you,

sam

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


Re: python interpreter on solaris 10

2006-09-25 Thread sam
to update:

i think i've tracked down the equivalent files on my pc. one opens the
interpreter in a white-backed text editor, the other at the
black-backed command prompt. i have equivalent files of the same size
on the workstation, which must be the same. does anyone know why i'm
getting 'there is no installed viewer capable of displaying the
document'?

i have no idea what i need, or where i can get it. any ideas?

sam

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


Re: python interpreter on solaris 10

2006-09-25 Thread sam
[EMAIL PROTECTED] wrote:
> > i think i've tracked down the equivalent files on my pc. one opens the
> > interpreter in a white-backed text editor, the other at the
> > black-backed command prompt. i have equivalent files of the same size
> > on the workstation, which must be the same. does anyone know why i'm
> > getting 'there is no installed viewer capable of displaying the
> > document'?
>
> What, exactly, are you doing to create this error?
>

searching on the java desktop for all files with 'idle' in them.
clicking on idle.py which is the same size as the equivalent file on my
pc (from which idle does open).
'could not open document "idle.py"' message comes up.

> What happens when you enter the line below at a command prompt?
>
> /usr/bin/python
not found

/usr/lib/python2.4/idlelib/idle.py
/usr/sfw/python2.3/idlelib/idle.py gives

'there is no action associated with "idle.py"'
configure gnome to associate application?

click yes:
edit file type window pops up.
program to run menu is empty.
browse is available. any ideas on what i need to choose?

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


Re: python interpreter on solaris 10

2006-09-25 Thread sam


> I would try to use the python executable located in /usr/bin if it is
> exists, otherwise use the python executable in /usr/sfw/bin.
>
> casevh

lordy lord, is that where it was. i just found it now. i had been
thinking that idle was the name of the python interpreter, not just the
IDE, hence my emphasis on it. python itself is indeed just in
/usr/sfw/bin, as you said.

a thousand thanks. i've got it on command line now.

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


how to reuse class deinitions?

2006-10-01 Thread sam
hello all,

pretty straightforward question here, i think. i'm experimenting with
classes and have written a File class that looks like it's worth
keeping for future use. however, i cannot work out where to put it for
this purpose or how to get it in.

i figured i'd try a bit of (un)inspired guesswork by putting it in my
module folder, appending sys.path to tell the interpreter where this
was, and importing it like a module. probably don't need to tell you
that that didn't work, but i'm drawing a blank in the tutorial and not
getting any luck in the archives here. maybe i'm just not searching
with the right words. it's late here and my brain's switching off...

cutting and pasting it into the interpreter is a bit of a bore. any
help?

much appreciated in advance,

sam

PS i've just reached first base with classes, and i think i'm starting
to see what the big deal is about OOP. it's like someone's turned a
light on.

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


Re: how to reuse class deinitions?

2006-10-01 Thread sam
should read 'definitions', of course. i hate stupid typos.

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


Re: how to reuse class deinitions?

2006-10-01 Thread sam


> What I do:
>
> For each new major version of python, in .../site-packages I make a
> directory "sdd" (my initials).  In it I put an empty file named
> "__init__.py".  When I have things I want to reuse, I put them in
> files named things like ".../site-packages/sdd/goodidea.py", and
> I get use of them in python programs like:
>
>  from sdd.goodidea import File
>  ...
>  
>  ...
>
> or (actually my current style):
>  from sdd import goodidea
>  ...
>  
>  ...
>

this is basically what i was trying to do. i just tried it again, with
a class_defs.py file in a folder i appended to the system path, itself
containing the class definition for File. then:

from class_defs import File

works fine.

nice to know i was on the right lines. thanks for the pointer!

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


Re: About the 79 character line recommendation

2006-12-05 Thread sam

Steve Bergman wrote:
> As I study Python, I am trying to develop good, Pythonic, habits.  For
> one thing, I am trying to keep Guido's the style guide in mind.
>
> And I know that it starts out saying that it should not be applied in
> an absolute fashion.
>
> However, I am finding that the 79 character line prescription is not
> optimal for readability.
>
> Certainly, cutting back from the length of lines that I used to use has
> *helped* readability.  But if I triy very hard to apply 79, I think
> readability suffers.  If this were just something that was an issue
> occasionally, I would just put it off to "know when to break the
> rules".  However, find myself going to 90 to 100 characters very
> frequently.  Now, if it were just me, I'd shoot for < 100.  However,
> the Python philosophy includes making code easier for others to read,
> as well.
>
> So, I was wondering what more accomplished Python programmers thought
> about this.
>
> While I'm on this general topic, the guide mentions a pet peeve about
> inserting more than one space to line up the "=" in assignment
> statements.  To me, lining them up, even if it requires quite a few
> extra spaces, helps readability quite a bit.  Comments?
>
> Thanks,
> Steve Bergman

I prefer to use 132 char per line, and like you I line up the = sign
for readability.
The reason for this convention arises from the fact that I am Dyslexic,
and this convention helps me double check my typing.

Sam Schulenburg

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


problems caused by very large for-loop

2006-12-07 Thread sam
hi all,

i am writing some software to model polymerisation kinetics and have
created a way of doing so which involves taking ever smaller slices of
time to model until some sort of convergence was observed in the
results.

so far so good, but i was using 'for i in the range(iterations):' a for
loop over each slice of time, where the number of iterations was
getting into the tens of millions. up until about 125,000,000 it
worked, then i got a MemoryError.

now i wasn't surprised to get a memory error eventually because what i
was doing was some serous number-crunching. but it didn't occur to me
where it was at first. i had to keep some results in memory to
calculate something at the end, but that was about a million integers,
not that hard with 512 Mb of RAM. then i thought it might be something
structural in the way python works, but i couldn't guess at what it
might be.

thinking about it a bit more, i remembered having read that the
for-loop declaration i used actually created a list of integers, which
would be eating up over half of my memory before i'd even started doing
anything. the program was creating a directory as instructed, then
doing nothing, just churning, which made it clear that the problem was
encountered right at the start of the program. that helped clear it up,
but i was surprised that something as innocuous as the for-loop was
creating such a problem. i changed it to a while-loop and it worked
fine.

has anyone else bumped up against this problem before? i suppose
for-loops with 250 million iterations are seldom used in most
applications. it was just the first time i'd ever solved a problem by
actually having some insight into how python works at a slightly lower
level.

anyway, sorry to be so long-winded. i'm just glad the damn thing's
working again... :)

sam

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


Re: problems caused by very large for-loop

2006-12-07 Thread sam
thanks, i'll remember that. it makes sense that there should be a way
of doing it...

sam

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


Re: Pyserial never read

2006-02-22 Thread sam
luca72 wrote:
> Thanks to all for the help,
>
> here you find the code, pls note if i use handshaking = 1 the
> application don't start.
> in the delphi configuratio of com port if i use or not handshaking the
> application work.
> Best Regards at all
>
> Luca
>
> import serial
> import win32file
> port = 2

Is port = 2 correct?
I thought that com ports under windows are designated as a string
"com1","com2",..etc.

> baudrate = 38400
> bytesize =serial.EIGHTBITS
> parity =serial.PARITY_ODD
> stopbits =serial.STOPBITS_TWO
> timeout = 1
> ser = serial.Serial(2, baudrate=38400, bytesize=8,
> parity=serial.PARITY_ODD, stopbits=2, timeout=3)
> ct = ''
> ch = ''
> a = self.textCtrl1.GetValue()
> ind = 0
> ind1 = 2
> lunghezza = len(a)
> while ind < lunghezza :
> b = a[ind:ind1]
> b = int(b,16)
> b = ~b
> c = ''.join([str((b >> Digit) & 1) for Digit in range(7,
> -1, -1)])
> c1 = c[0:4]
> c2 = c[4:]
> c1 = c1[3:] + c1[2:3] + c1[1:2] + c1[0:1]
> c2 = c2[3:] + c2[2:3] + c2[1:2] + c2[0:1]
> c1 = hex(int(c1,2))
> c2 = hex(int(c2,2))
> c1 = c1[2:]
> c2 = c2[2:]
> c = c2+c1
> ct = ct + c
> ind = ind + 2
> ind1 = ind1 + 2
> c = int(c,16)
> c = chr(c)
> ch = ch + c
>
>
> ser.write(ch)
>
> elf.textCtrl2.SetValue(ct)
> ser.readline()
 You might want to try using ser.read() instead of ser.readline() as
you may not be getting  linefeed carrage return characters . I usually
setup a buffer to scan for the characters I expect.

>
>
>
> Pls.Note i hove also try with read(number of byte ) with inWaiting(),
> flush  etc
> 
> 
> But no result.
> 
> Thanks Luca

Hope this helps
Sam Schulenburg

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


  1   2   3   4   >