Problem with wxPython form

2023-03-10 Thread Chris
Hi everyone. I'm new to Python and wxPython. I've got a form I use to 
calculate the Sq In of a leather project.


I'm using python 3.9.13 and wxPython 4.20

I'm having the following issues:
1) When I come into the form, no grid cell has the focus set - I start 
typing and nothing happens. I have to click the cell.
If I hit Tab or Enter, the OnKeyDown fires, but does not move to the 
appropriate cell - it does nothing but run the update and move off of 
the current cell.

The action I'm trying to make is this
ENTER KEY: Always go down 1 row and to col 0
TAB, if Col 0 Move to Col 1 on same row, if Col 1 go to Row +1, Col 0
I also need to have what3ever cell it is supposed to land on to get the 
focus so I can just type.

Currently I have to click in each cell I want/need to add.
There could be up to 20 pieces of leather with differing sizes, so in 
order to accurately calculate the Sq In, I need to get all the 
measurements in.
The form, one of several tabs, comes up and does everything else I've 
coded for great. Just no navigation.

Can anyone assist? Here is the module with the form

/***/

'''

Module Name : alwsqin.py

Author      : Chris Anderson

Create Date : 03/10/2023

Description : This module contains the Sq In/MM/CM of leather used

This file is Copyright Anderson Leather Works (c) 2023

'''

//

/#/

/# File Last Update and Person/

/#/

/#***/

/# Imports/

/import/wx

/#from Imports/

/from/alwlogic /import/leather_sqin

/class/LeatherSqInPanel(wx.Panel):

'''

Name        : LeatherSqInPanel

Author      : Chris Anderson

Create Date : 02/23/2023

Description : Panel for the 'Leather Sq In Calculator

              in Leatherworking Cost Estimator app

'''

dbTableName /=/'None'

/def/__init__(self, parent):

    wx.Panel.__init__(/self/, parent)

/self/.ls /=/leather_sqin

/self/.grid /=/wx.grid.Grid(/self/, size/=/(600, 515))

/self/.grid.CreateGrid(30, 6)

/# Set column labels/

/self/.grid.SetColLabelValue(0, "Length")

/self/.grid.SetColLabelValue(1, "Width")

/self/.grid.SetColLabelValue(2, "Total")

/self/.grid.SetColLabelValue(3, "Grand Total")

/self/.grid.SetColLabelValue(4, "Type")

/self/.grid.SetColLabelValue(5, "Select Calc Method")

/for/col /in/range(/self/.grid.GetNumberCols()):

/self/.grid.AutoSizeColumn(col)

/self/.grid.EnableEditing(True)

/# Set dropdown choices for column 5, row 0/

    types /=/["Sq In", "Sq Cm", "Sq Mm"]

/self/.type_dropdown /=/wx.ComboBox(/self/.grid, choices/=/types, 
style/=/wx.CB_DROPDOWN/|/wx.CB_READONLY)


/self/.type_editor /=/wx.grid.GridCellChoiceEditor(choices/=/types)

/self/.grid.SetCellEditor(0, 5, /self/.type_editor)

/self/.grid.SetCellRenderer(0, 5, wx.grid.GridCellAutoWrapStringRenderer())

/# Set initial value for Type column/

/self/.grid.SetCellValue(0, 5, types[0])

/# Make Total and Grand Total cells read-only/

/for/i /in/range(/self/.grid.GetNumberRows()):

/self/.grid.SetReadOnly(i, 2)

/self/.grid.SetReadOnly(i, 3)

/# Set Type column values/

/self/.grid.SetCellValue(0, 4, "Sq In")

/self/.grid.SetCellValue(1, 4, "Sq Cm")

/self/.grid.SetCellValue(2, 4, "Sq Mm")

/# Populate grid with data from LeatherSqIn object/

/for/i, row /in/enumerate(/self/.ls.get_data()):

/for/j, val /in/enumerate(row):

/self/.grid.SetCellValue(i, j, str(val))

/if/j /==/0: /# Check if first column/

/self/.grid.SetCellValue(i, j/+/1, "Sq In") /# Set default value for 
column 2/


/if/i /==/0/and/j /==/5:

/self/.grid.SetCellEditor(i, j, 
wx.grid.GridCellChoiceEditor(choices/=/["Sq In", "Sq Cm", "Sq Mm"]))


/else/:

/self/.grid.SetCellValue(i, j, str(val))

/# Calculate totals and grand total/

/for/i, row /in/enumerate(/self/.ls.get_data()):

/self/.ls.calculate_total(row)

    grandTotal /=/0.0

    total /=/0.0

/self/.ls.calculate_grand_total(grandTotal, total)

/# Bind events/

/self/.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGED, /self/.OnCellChange)

/self/.grid.Bind(wx.EVT_KEY_DOWN, /self/.OnKeyDown) /# Bind the key down 
event/


/# Add grid and button sizers to top sizer/

    sizer /=/wx.BoxSizer(wx.VERTICAL)

    sizer.Add(/self/.grid, 1, wx.ALL)

/self/.SetSizer(sizer)

/# Set grid line width for last column to 0/

/self/.grid.SetCellHighlightPenWidth(0)

/# Set grid cursor and focus/

/# Select cell R0C0 and set focus/

    wx.CallAfter(/self/.grid.SetGridCursor, 0, 0)

    wx.CallAfter(/self/.grid.MakeCellVisible, 0, 0)

    wx.CallAfter(/self/.grid.SetFocus)

/def//OnCellChange/(self, event):

print("OnCellChange called")

    row, col /=/event.GetRo

ctypes struct alignment specification

2020-11-10 Thread Chris
I am working on a CUDA python API using ctypes. Within CUDA there are vector 
type structs defined (float2, float3, float4, int2, int3, int4, ...), all of 
which have an alignment specification (example of how this is specified 
https://stackoverflow.com/questions/12778949/cuda-memory-alignment/12779757) . 
I want to include these structs in the Python api but as far as I can tell, 
ctypes does not have a way to specify a structure's alignment in the same 
fashion (the #pragma pack(n) alignment feature that ctypes does support does 
not do the same thing). If the alignment specification is omitted on the Python 
side, the structure's alignment can be mismatched between the host (CPU) and 
device (GPU) causing segfaults/etc. . Is this something that could be added to 
ctypes or is it not feasible/possible?
-- 
https://mail.python.org/mailman/listinfo/python-list


in-memory db? gadfly?

2005-09-22 Thread chris
I'm looking for a completely in-memory sql db.  I have seen gadfly, but
its startup method seems to require a directory for the on-disk file
storage.  I have a script and I want to create a database/tables in the
script, insert some data (not much), and execute some queries, all
in-memory.  Don't need to persist anything.  Possible, or am I just
talking crazy here?

Thanks,
Chris

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


Re: in-memory db? gadfly?

2005-10-07 Thread chris
sqlite worked perfectly, thanks.

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


Re: in-memory db? gadfly?

2005-10-07 Thread chris
sqlite worked perfectly, thanks.

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


HELP! py2exe error - No module named decimal

2005-10-21 Thread Chris
I've just completed a project using the following (Windows XP, python 
2.4.1, wxpython 2.6, and pymssql 0.7.3). The program runs great, but 
after I convert it to an exe (required for this project), it gives me 
the following error when I try to run it.

Traceback (most recent call last):
  File "EstUpdate.py", line 6, in ?
  File "frmSplash.pyc", line 9, in ?
  File "pymssql.pyc", line 23, in ?
  File "_mssql.pyc", line 9, in ?
  File "_mssql.pyc", line 7, in __load
ImportError: No module named decimal

However, when I look in c:\python24\lib on the machine which ran py2exe, 
I see decimal.py and decimal.pyc.

Can someone please help with this? I'm supposed to start testing the 
program today and I can't seem to move past this first step.

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


Re: HELP! py2exe error - No module named decimal

2005-10-21 Thread Chris
That was it. 

Thank you so much!

Chris

In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] 
says...
> FYI there is a separate newsgroup for py2exe at
> gmane.comp.python.py2exe.  You may want to post
> there also.
> 
> Just as a suggestion, put an import decimal at
> the top of your program.  It looks like _mssql
> might be doing dynamic imports in __load method
> which will "confuse" py2exe because it can't
> know about dynamic imports which happen at
> runtime.
> 
> -Larry Bates
> 
> Chris wrote:
> > I've just completed a project using the following (Windows XP, python 
> > 2.4.1, wxpython 2.6, and pymssql 0.7.3). The program runs great, but 
> > after I convert it to an exe (required for this project), it gives me 
> > the following error when I try to run it.
> > 
> > Traceback (most recent call last):
> >   File "EstUpdate.py", line 6, in ?
> >   File "frmSplash.pyc", line 9, in ?
> >   File "pymssql.pyc", line 23, in ?
> >   File "_mssql.pyc", line 9, in ?
> >   File "_mssql.pyc", line 7, in __load
> > ImportError: No module named decimal
> > 
> > However, when I look in c:\python24\lib on the machine which ran py2exe, 
> > I see decimal.py and decimal.pyc.
> > 
> > Can someone please help with this? I'm supposed to start testing the 
> > program today and I can't seem to move past this first step.
> > 
> > Thanks!!
> > Chris
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


/usr/lib/python2.4/posixfile.py error

2005-11-03 Thread Chris
Hi, 

Wonder if anyone can help me?

I am trying to run a perl script but I keep getting this error:

/usr/lib/python2.4/posixfile.py:59: DeprecationWarning: The posixfile 
module is obsolete and will disappear in the future
  DeprecationWarning)

I am running Ubuntu Hoary 5.10.  I'll try the same script on my gentoo 
box at work tommorrow, but really would like to run this script asap.

Any ideas on why it's failing on that python module?

Any ideas greatfully received,

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


Re: /usr/lib/python2.4/posixfile.py error

2005-11-05 Thread Chris
In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> Chris wrote:
> > Wonder if anyone can help me?
> 
> I very much doubt that, with as little information you gave us.
> 
> > I am trying to run a perl script but I keep getting this error:
> > 
> > /usr/lib/python2.4/posixfile.py:59: DeprecationWarning: The posixfile 
> > module is obsolete and will disappear in the future
> >   DeprecationWarning)
> 
> It's very strange that you get a Python error when running a Perl
> script.

So I thought ;)

However, it's a perl script that invokes python.  

http://search.cpan.org/~rprice/Nokia-File-NFB-0.01/lib/Nokia/File/NFB.pm

> > Any ideas on why it's failing on that python module?
> 
> It's not failing. It's a warning, not an error. The warning is
> that the Python code you are running uses the posixfile module,
> and it should be rewritten to stop doing so, as the posixfile
> module will go away eventually.
> 

Ok, many thanks.  I got it working in the end, appears that the nfb.py 
script requires the file it is processing to be in the same directory.  
Which is quite annoying, but at least I know how to sort it now.

Many thanks for your quick reply and apologies for my late one :(

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


Comparison problem

2005-11-26 Thread Chris
Hi,

I'm new to python, and I'm trying to write a small python script for a
webpage.  The script opens up a file called inventory, reads the
contents, and checks the contents against the data from the form in my
webpage.  Now I have to do some slicing to get the name of the form
elements (in this case, checkboxes), to resemble the values in the
inventory file.  Here's my python part:

#!/usr/local/bin/python
import cgi
import types
from Cookie import *
form=cgi.FieldStorage()
user_answer=[]
error='false'
item=''
qty=''
def main():
  print"Content-type: text/html\n"
  i=open("inventory","r")
  keys=form.keys()
  for key in keys:
   field=form[key]
   if type(field)==types.InstanceType:
item=field.value
if item[0:1]=="-":
 item=item[ :-7]
 item=item[1:]
 infile=open("inventory","r")
 while infile:
  dummy=infile.readline()
  if dummy=='':break
  print item
  print ", "+dummy
  if (dummy == item): 
   print"Found it"
  else:
   print"Didn\'t Find it"
  print ""
 infile.close()
else:
 #print"Quantity: "
 #print item
 print""
#print field.value
   else:
print"BAD"
main()

Let me know if more information is needed.  Any assistance will be
greatly appreciated.

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


Re: urllib and proxy

2005-01-27 Thread chris
This was helpful.  After reading this, I realized you can also just add
this atop whatever script imports urllib.  Just add after "import
urllib":

# Disable proxy use.
urllib.getproxies = lambda x = None: {}
-Chris
http://www.fetidcascade.com/

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


Help with web dashboard

2005-01-27 Thread Chris
I've written some python scripts to handle different tasks on my Windows 
network. I would like for them to be accessible via a single web page 
(kind of like a dashboard) but have the scripts run on the web server  
(also a Windows box).

Can anyone recommend a way (web server / language / method) of doing 
this? 

Security is important since this page will be accessible inside the 
company, but only people with the appropriate user name / password 
should be able to run the scripts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with web dashboard

2005-01-28 Thread Chris
In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> Ifd you want to use standard CGI I've written a CGI user
> authentication/management module called logintools.
> 

Would this be preferred (or easier) than using an application server 
(ie. Zope or Webware)? 

If possible, I think it would be nice if the security aspect of it was 
already built-in so I would not need to write/test it myself.

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


urllib2.urlopen hangs, urllib.urlopen works?

2005-07-10 Thread Chris
hello,
I have an odd behaviour. I try to download some files connected to a 
specific webpage (e.g. all stylesheets) with
urllib2.urlopen(x)
This seems to hang on the 2nd file or so.

Doing the exact same thing via
urllib.urlopen(x)
does work without a hitch...

I don't really to use urllib instead of urllib2 but am wondering where 
the problem is and if there is a workaround (or just my own stupidity)?
Also with urllib I cannot send my own user-agent header as i wanted to do...

thanks for any hint!

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


Multivariable polynomials

2005-07-12 Thread Chris
Does anyone know of a good standalone implementation of multivariable
polynomials in python?

Thanks,
Chris

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


Re: Multivariable polynomials

2005-07-13 Thread Chris
Fantastic. May I ask what you are hoping to use it for?

I checked out Scientific python:
http://starship.python.net/~hinsen/ScientificPython/

It has a module with multivariate polynomials with support for a good
functionality but I think the input style won't suit my needs. In any
case, perhaps it will be helpful for you.

Chris

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


Could anyone write a small program to log the Signal-to-Noise figures for a Netgear DG834 router?

2005-07-18 Thread Chris
Could anyone write a small program to log the Signal-to-Noise figures 
for a Netgear DG834 router?

I have been getting very variable SNR readings - and I would like to 
collect some evidence to analyse.

What is needed is a program that logs into the router's html page every 
minute, and then extracts the time and the SNR figure, and writes a line 
of a text file.

I reckon it would be useful to many people.
-- 
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


OO design

2005-07-19 Thread chris
I've been scripting with python for a while now. Basically writing a few
functions and running in the ipython shell. That's been very useful. But the
more I do this the more I see that I'm doing more or less the same thing
over and over again. So its feels like I need to get into class programming
with all its attendant benefits. However my biggest problem is a conceptual
one. I just can't get my head around defining suitable classes, how they
aquire data and communicate with each other. I'm hoping some of you python
lamas out there might be able to share some of your wisdom on the subject.

What I basically do is a lot of the following::

1. get arbitrary numerical data (typically large data sets in columnar
format or even via COM from other packages. I generally have to deal with
one or more sets of X,Y data)
2. manipulate the data (scaling, least squares fitting, means, peaks,
add/subtract one XY set from another etc)
3. plot data (original set, results of manipulation, scatterplot, histograms
etc  - I use matplotlib)
4. export data (print, csv, shelve)

I have no problem writing bits of functional code to do any of the above.
But for the life of me I can't see how I can hook them altogether in an OO
based framework that I can build and extend (with more data formats,
manipulations, GUI etc).

When I think about what I should do I end up with a class XY that has a
method for everything I want to do eg.

class XY:
  def read_file
  def scale_data
  def plot_data
  def shelve_data

But somehow that doesn't feel right, especially when I expect the number of
methods will grow and grow, which would make the class very unwieldy.

Even if that was a legitimate option, I don't understand conceptualy how I
would, for example, plot two different XY objects on the same graph or add
them together point by point. How do two different XY objects communicate
and how do you deal with the thing that they must have in common (the plot
screen for example).

Clearly I'm having some conceptualisation problems here. Hope someone can
shed some light on the subject

bwaha.



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


Re: Could anyone write a small program to log the Signal-to-Noise figures for a Netgear DG834 router?

2005-07-19 Thread Chris
In article <[EMAIL PROTECTED]>, 
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes
>Chris, How would a wireless router show a signal to noise ratio?
>Especially if it's providing the signal?

The Netgear DG834 is a wired router.
Its statistics page gives line loss and SNR.
-- 
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Could anyone write a small program to log the Signal-to-Noise figures for a Netgear DG834 router?

2005-07-19 Thread Chris
In article <[EMAIL PROTECTED]>, 
Steven D'Aprano <[EMAIL PROTECTED]> writes
>On Tue, 19 Jul 2005 07:24:19 +0100, Chris wrote:

>> Could anyone write a small program to log the Signal-to-Noise figures
>> for a Netgear DG834 router?

>Are you offering to pay somebody to do it, or just suggesting a project
>for some Python programmer who is bored and looking for a small project to
>work on out of love?

Yes, Steven, the latter.  Sometimes programmers need an idea for a 
project - and, for them, knowing that someone would actually value what 
they did might make it more fun for them.
-- 
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO design

2005-07-20 Thread chris
Extremely grateful for all the responses. I've pasted them all into a
document and can now read all your valuable ideas together. Even at a first
reading they have already helped clarify my thinking.

Also minor clarifications::

> I'm hoping some of you python
> lamas out there might be able to share some of your wisdom on the subject.

lama = guru = teacher(not a furry animal, although my dog has certainly
taught me a few tricks ... like when to take her for a walk, when to play
ball, and when its time for a tummy rub.)

> bwaha

be well and happy always






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


Using win32com for web automation

2005-07-26 Thread Chris
Hi,

I'm trying to figure out how to submit javascript forms using win32com
in order to complete repetitive processes.

The Webpage Source: (I tried to include only the important stuff)
--


  function mainPageOnLoad() {
initLogin();
setEnterToSubmit('loginForm','loginrequest');
  }









  
  Name: 
  


  
  Password: 
  



  
  



  

--

My code so far is this:
--
from win32com.client import Dispatch
from time import sleep

ie = Dispatch('InternetExplorer.Application')
ie.Visible = 1
ie.Navigate("http://ispds-sepsr.prv:7500/cs/welcome.jsp";)

while ie.ReadyState != 4:
sleep(1)

doc = ie.Document

while doc.readyState != "complete":
sleep(1)

doc.loginForm.name.value = 'username'
doc.loginForm.password.value = 'password'
doc.loginForm.loginform.action = '/cs/login.do'
-

Well it doesn't seem to work like other javascript sites (eg. like the
google.ca form)which is where i snagged the script from.
I don't really have a clue about this module, or even javascript so any
help would be appreciated.

P.S. sorry about the mess

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


Regex for nested {}

2005-07-28 Thread Chris
hello,
I have a problem matching nested levels of {}, example:

 >>> import re
 >>> text = """
outer {
inner1 { ... }
inner2 { ... }
}
simple { ... }
"""


 >>> r = re.compile(r"""
(   # OPTION1
.*? # begin
\{  # starting {
(?: \{.*?\} )*  # inner groups
\}  # ending }
)|  # OR
(   # OPTION2
.*? { .*? } # simple group may also happen
)
""", re.DOTALL|re.IGNORECASE|re.UNICODE|re.VERBOSE )


 >>> r.findall(text)

 >>> [('', '\n\touter { \n\t\tinner1 { ... }'), ('', ' \n\t\tinner2 { 
... }'), ('', '
  \n\t}\n\tsimple { ... }')]


the regex I currently use stops at the first closing } but what I am 
looking for is a result as:

[
"outer {
inner1 { ... }
inner2 { ... }
}",
"simple { ... }"
]

is something like that possible?

thanks for any hint
chris
-- 
http://mail.python.org/mailman/listinfo/python-list


showing help(M) when running module M standalone

2005-07-30 Thread Chris
hello,
I have a small module which only contains some utility functions. when 
running this standalone I would like to show the module docs and each 
function docs, as if doing

import M
help(M)

I came up with the following but I reckon there is a much simpler way?

if __name__ == '__main__':
 print __doc__
 print "\nFUNCTIONS:\n"
 for x in __all__:
 print x
 exec "print " + x + ".__doc__"

Works but does not seem right using exec for such a task.

any hint would be great!

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


Re: showing help(M) when running module M standalone

2005-07-30 Thread Chris
Dan Sommers wrote:
> On Sat, 30 Jul 2005 17:04:50 +0200,
> Chris <[EMAIL PROTECTED]> wrote:
> 
> 
>>hello,
>>I have a small module which only contains some utility functions. when
>>running this standalone I would like to show the module docs and each
>>function docs, as if doing
> 
> 
>>  import M
>>  help(M)
> 
> 
>>I came up with the following but I reckon there is a much simpler way?
> 
> 
>>if __name__ == '__main__':
>> print __doc__
>> print "\nFUNCTIONS:\n"
>> for x in __all__:
>> print x
>> exec "print " + x + ".__doc__"
> 
> 
>>Works but does not seem right using exec for such a task.
> 
> 
> So don't use exec.
> 
> 
>>any hint would be great!
> 
> 
> for x in __all__:
> print x.__doc__

I tried that, problem is that __all__ containts strings...

> 
> HTH,
> Dan
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: showing help(M) when running module M standalone

2005-07-30 Thread Chris
hello,
thanks for all suggestions,

if __name__ == '__main__':
 __name__ = 'MODULENAME'
 help(__name__)

does actually work any even shows the modulename it should.

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


Re: Printing Docstrings Without Importing

2005-08-02 Thread Chris
Fuzzyman wrote:
> This seems to scratch several people's itches.


As I understand it it is something like generating "pythondoc" like javadoc?
Should be pretty easy to develop something a bit more polished than 
Bengt's solution (or based on it of course) with maybe similar to 
javadoc framesets for a navigational list etc.

But usn't there something like that from the docutils project (I must 
admit I should have googled for it but have not have the time yet).
I was looking for something to but found only epydoc yet with yet 
another of its own markup, docutils being something like a standard for 
python (at least that's what I thought) would be really nice for it.


chris

sorry if i totally misunderstood the question...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get the return code when piping something to a python script?

2005-08-17 Thread chris
I use the following when I have an external command to do:

#
def doCommand( cmd,forked=False,runFrom=None ):
"""
Do a command, and return the (stdout+stderr) and the exit status.
This was written to work both on Windows and *nix, and in the
limited
testing to which it has been subjected, it works well.
"""

import sys;
import os;

exitcode = None;
output   = None;
origin   = None;

if runFrom:
origin = os.getcwd()
try:
os.chdir( runFrom );
except:
pass;

# "forked" to us means "run in background and forget about it".
The
# method of execution is the same on both windows and unix
if forked:
theCommand = cmd.split()[0];
theArgs= cmd.split(); # Include the cmd itself in the
v.
  # Guaranteed to be a list.

# P_DETACH: we don't want the process to be our child, and
# we don't want to know what happens to it... Some father!
exitstatus = os.spawnve(
os.P_DETACH,theCommand,theArgs,os.environ );

# if we're not spawning off a separate child, then we do care about
# the results of the process, and execution is different between
# windows and unix
else:
if( sys.platform == "win32" ):
import win32pipe;
(stdin,stdout) = win32pipe.popen4( cmd,'t' );

stdin.close();
output = stdout.read();
try:
exitcode = stdout.close() or 0;
except IOError:
exitcode = ( -1 );

else:
import commands;
( exitstatus,output ) = commands.getstatusoutput(cmd)

# exitstatus is a smashing of the return value and any
signal
# sent back from the child process... break them out.
exitcode = (( exitstatus >> 8) & 0xFF );
signal   = (  exitstatus   & 0xFF );


if runFrom:
#return( 0,"Returning to %s from %s" %(origin,os.getcwd()) )
os.chdir( origin );

return( exitcode,output );
#---

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


Regular Expression IGNORECASE different for findall and split?

2005-09-06 Thread Chris
hello,
I have question about the re.I option for Regular Expressions:

 >>> import re
 >>> re.findall('x', '1x2X3', re.I)
['x', 'X']

as expected finds both lower and uppercase x


 >>> re.split('x', '1x2X3', re.I)
['1', '2X3']
 >>> re.split('x', '1x2X3')
['1', '2X3']

I expected ['1', '2', '3'] but in this case re.I bahaves exactly as not 
present at all...

Is that an expected behaviour or a fault?
Running Python 2.4.1 on Windows XP

thanks for any hint
chris

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


Re: Ignoring ampersand(&) as a special character in xml

2005-09-06 Thread Chris
Thierry Lam wrote:
> Let's say I have the following xml tag:
> 
> a & b
> 
> Currently, an xml parser will treat & as a special character.  Does
> anyone know the special characters to use around the ampersand so that
> the xml parser can treat "a & b" as a whole value?
> 
> Thanks
> Thierry
> 

Simple use the XML Entity for & which is &

a & b

You could use CDATA sections too but they seem to have the effect on 
people ignoring that the containing strings are actually literary what 
they seem (in this case "a & b") and not what they really are ("a & 
b")...

chris

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


Re: Ignoring ampersand(&) as a special character in xml

2005-09-06 Thread Chris
Chris wrote:
> Thierry Lam wrote:
> 
>> Let's say I have the following xml tag:
>>
>> a & b
>>
>> Currently, an xml parser will treat & as a special character.  Does
>> anyone know the special characters to use around the ampersand so that
>> the xml parser can treat "a & b" as a whole value?
>>
>> Thanks
>> Thierry
>>
> 
> Simple use the XML Entity for & which is &
> 
> a & b
> 
> You could use CDATA sections too but they seem to have the effect on 
> people ignoring that the containing strings are actually literary what 
> they seem (in this case "a & b") and not what they really are ("a & 
> b")...

should read before posting..., of course the other way round:
some people seem to ignore the visible "a & b" is not the actual "a 
& b" in CDATA sections...

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


__dict__ of object, Was: Regular Expression IGNORECASE different for findall and split?

2005-09-06 Thread Chris
Peter Otten wrote:
> Chris wrote:
> 
> 
>> >>> re.split('x', '1x2X3', re.I)
>>['1', '2X3']
> 
> 
> 
>>I expected ['1', '2', '3'] but in this case re.I bahaves exactly as not
>>present at all...
> 
>  
> 
>>Is that an expected behaviour or a fault?
> 
> 
> This is expected:
> 
> 
>>>>help(re.split)
> 
> Help on function split in module sre:
> 
> split(pattern, string, maxsplit=0)
> Split the source string by the occurrences of the pattern,
> returning a list containing the resulting substrings.
> 
> You are setting maxsplit to
> 
> 
>>>>re.I
> 
> 2
> 
> Use re.compile() to get the desired behaviour:
> 
> 
>>>>re.compile("x", re.I).split("1x2X3")
> 
> ['1', '2', '3']
> 
> Peter

thanks, I should read the docs but

but more of a basic question following, I was doing the following before:

method = 'split' # came from somewhere else of course
result = re.__dict__[method].(REGEX, TXT)

precompiling the regex

r = compile(REGEX)

does give an regex object which has the needed methods

print dir(r)
['__copy__', '__deepcopy__', 'findall', 'finditer', 'match', 'scanner', 
'search', 'split', 'sub', 'subn']

but how do I evaluate them without explicitly calling them?

result = r.__???MAGIC???__[method](TXT)

obviously I am not a Python pro ;)

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


Re: __dict__ of object, Was: Regular Expression IGNORECASE differentfor findall and split?

2005-09-07 Thread Chris
Fredrik Lundh wrote:
> Chris <[EMAIL PROTECTED]> wrote:
> 
> 
>>but more of a basic question following, I was doing the following before:
>>
>>method = 'split' # came from somewhere else of course
>>result = re.__dict__[method].(REGEX, TXT)
>>
>>precompiling the regex
>>
>>r = compile(REGEX)
>>
>>does give an regex object which has the needed methods
>>
>>print dir(r)
>>['__copy__', '__deepcopy__', 'findall', 'finditer', 'match', 'scanner',
>>'search', 'split', 'sub', 'subn']
>>
>>but how do I evaluate them without explicitly calling them?
>>
>>result = r.__???MAGIC???__[method](TXT)
>>
>>obviously I am not a Python pro ;)
> 
> 
> I really don't understand why you think you have to write
> your RE code that way, but the mechanism you're looking
> for is getattr:
> 
> result = getattr(r, method)(TXT)
> 

thanks (also to Steven) for the info, that is exactly what i was looking 
for.

reason is that I built a small UI in which the user may choose if he 
want to do a split, findall (and maybe later others like match or 
search). So the method name comes in "from the UI". I could of course 
use if/elif/else blocks but thought getattr should be shorter and 
easier. I was not really aware of getattr which I was looking for on 
other occations before...

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


Need help with C extension module

2005-09-07 Thread chris
This is my first attempt at undertaking a C extension module.  I want
to wrap an existing C library so I can call the functions from Python.
There are only two functions I'm interested in calling.  I did mess
with Pyrex a bit and Swig, to no avail, so I turned to doing it by
hand.  Using the example in Programming Python, I did get the easier of
the two functions working--only takes a string parameter.  I'm stuck
now on the other function and not sure how to wrap it, because it
involves some structs.  Here's a simplified version of the C:

struct In
{
  int x;
  char* s;
  ... (only primitive data types)
};

struct Out
{
  int y;
  char* s;
  ... (only primitive data types)
};

Out* func(In* x, Out* y);

So the function takes pointers to the two structs, and fills out the
output struct and also returns the pointer to it.  I would envision the
Python looking like

in = In()
in.y = 1
in.s = "abc"
...

out = func(in)

maybe?  Just no idea how to deal with the structs in the C extension
module code.

Any tips appreciated.

Thanks,
Chris

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


Re: Need help with C extension module

2005-09-07 Thread chris
Any tips on what the pyrex should look like for my example?

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


Re: Need help with C extension module

2005-09-07 Thread chris
Many thanks Robert.  That will be a good starting point.

-Chris

http://auslunch.com/
http://fetidcascade.com/
http://strombergers.com/python/

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


Re: Need help with C extension module

2005-09-08 Thread chris
Ok, I found further examples on the Internet and got something working
(it seems), but I have a question about the memory management.  The
example I found did not include any of the PyMem_... functions.

Here's roughly what I have working:

cdef extern from "my.h":
  cdef struct inputs:
char   *x

  cdef struct outputs:
  int y

  outputs *func(inputs *x, outputs *y)
  int init(char* fname)

class Analyzer:
  def __init__(self, fname):
init(fname)

  # inp is my python "Inputs" object.
  def myfunc(self, inp):
cdef inputs* i
i.x= inp.x

cdef outputs* o
o = func(i, o)
return o.y

class Inputs:
  def __init__(self):
self.x = ""

So there is no explicit memory management going on there as in Robert's
example.  Is this ok?  

Thanks,
Chris

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


Re: __dict__ of object, Was: Regular Expression IGNORECASE differentfor findall and split?

2005-09-08 Thread Chris
Mike Meyer wrote:
> Chris <[EMAIL PROTECTED]> writes:
> 
>>Fredrik Lundh wrote:
>>
>>>Chris <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>>but more of a basic question following, I was doing the following before:
>>>>
>>>>method = 'split' # came from somewhere else of course
>>>>result = re.__dict__[method].(REGEX, TXT)
>>>>
>>>>precompiling the regex
>>>>
>>>>r = compile(REGEX)
>>>>
>>>>does give an regex object which has the needed methods
>>>>
>>>>print dir(r)
>>>>['__copy__', '__deepcopy__', 'findall', 'finditer', 'match', 'scanner',
>>>>'search', 'split', 'sub', 'subn']
>>>>
>>>>but how do I evaluate them without explicitly calling them?
>>>>
>>>>result = r.__???MAGIC???__[method](TXT)
>>>>
>>>>obviously I am not a Python pro ;)
>>>
>>>I really don't understand why you think you have to write
>>>your RE code that way, but the mechanism you're looking
>>>for is getattr:
>>>result = getattr(r, method)(TXT)
>>>
>>
>>thanks (also to Steven) for the info, that is exactly what i was
>>looking for.
>>
>>reason is that I built a small UI in which the user may choose if he
>>want to do a split, findall (and maybe later others like match or
>>search). So the method name comes in "from the UI". I could of course
>>use if/elif/else blocks but thought getattr should be shorter and
>>easier. I was not really aware of getattr which I was looking for on
>>other occations before...
> 
> 
> So why is the UI returning strings, instead of code objects of some
> kind?
> 
> http://cthedot.de/retest/

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


Creating a list of Mondays for a year

2005-09-18 Thread Chris
Is there a way to make python create a list of Mondays for a given year?

For example,

mondays = ['1/3/2005','1/10/2005','1/17/2005','1/24/2005',
'1/31/2005','2/7/2005',   ... ]

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


Re: Creating a list of Mondays for a year

2005-09-19 Thread Chris
Thanks to everyone for your help!

That fit the need perfectly.

In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> Is there a way to make python create a list of Mondays for a given year?
> 
> For example,
> 
> mondays = ['1/3/2005','1/10/2005','1/17/2005','1/24/2005',
> '1/31/2005','2/7/2005',   ... ]
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python versus Perl ?

2005-02-09 Thread chris
[EMAIL PROTECTED] wrote:
> I've read some posts on Perl versus Python and studied a bit of my
> Python book.
>
>  I'm a software engineer, familiar with C++ objected oriented
> development, but have been using Perl because it is great for pattern
> matching, text processing, and automated testing. Our company is
really
> fixated on risk managnemt and the only way I can do enough testing
> without working overtime (which some people have ended up doing) is
by
> automating my testing. That's what got me started on Perl.
>
>  I've read that many people prefer Python and that it is better than
> Perl. However, I want to ask a few other questions.
>

This doesn't directly address your questions, but may be useful for
you, being a C++ programmer.

http://www.strombergers.com/python/

It is biased towards Python, obviously, but shows some practical
differences between Python and Perl that may be of interest.

-Chris

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


Re: Python and version control

2005-02-09 Thread Chris
In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...



> I don't know that you'll find a common approach.  I use Subversion for 
> version control.  For larger projects, I use Eclipse with the Pydev 
> plugin for editing, and the Subclipse plugin for talking to Subversion. 
>   For smaller things, I usually just edit with SciTE and use the 
> TortoiseSVN Explorer extension or the command-line utilities for 
> checkins and updates.
> 
> Peace,
> Joe
> 
Hi Joe,

I'm curious. Why do you only use Eclipse for big projects? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python COM Makepy Excel 9.0 error

2005-02-10 Thread Chris
Thank you!  That did the trick.

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


Re: Python and "Ajax technology collaboration"

2005-02-24 Thread Chris
Does anyone else have any Nevow examples?


In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> aurora <[EMAIL PROTECTED]> wrote:
> 
> > It was discussed in the last Bay Area Python Interest Group meeting.
> > 
> > Thursday, February 10, 2005
> > Agenda: Developing Responsive GUI Applications Using HTML and HTTP
> > Speakers: Donovan Preston
> > http://www.baypiggies.net/
> > 
> > The author has a component LivePage for this. You may find it from  
> > http://nevow.com/. Similar idea from the Javascript stuff but very Python
> > centric.
> 
> As an example for that technology (LivePage) I have this:
> 
> http://vercingetorix.dyndns.org:20080/
> 
> Which is an online forum where the "Quote & Reply" function is done with
> XMLHttpRequest and Python.
> 
> Implementing this stuff in the forum with Nevow ( the framework created
> by Donovan who I help to develop ) was almost effortless. 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nevow examples

2005-02-25 Thread Chris
Does anyone know of a site(s) that shows examples of what you can do 
with Nevow? I'm not necessarily referring to code, but what it can do 
over the web. (Something I can show my boss if needed.)




In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> 
> There was a request for nevow examples.  Nevow is a fantastic 
> web-development framework for Python.
> 
> I used nevow to create http://www.scipy.org/livedocs/
> 
> This site uses nevow and self introspection to produce (live) 
> documentation for scipy based on the internal docstrings.   It would be 
> nice to add the capability for users to update the documentation through 
> the web-site.  But, that functionality is not complete.
> 
> The code itself is available in the util directory of scipy which can be 
> checked out of CVS (or browsed).  Go to http://www.scipy.org  for mor 
> details.
> 
> -Travis Oliphant
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


memory leaks with ctypes LoadLibrary ?

2005-03-01 Thread chris
What is the proper way to use ctypes to access an exported Function in
a dll file on windows?  I must be missing something because I get
memory leaks when I  use it:

import ctypes
import gc

gc.enable()
gc.set_debug(gc.DEBUG_LEAK)
lib = ctypes.windll.LoadLibrary("H:\lib\mylib.dll")
fn = lib.myfn
fn("test")
del fn
del lib
gc.collect()
gc: uncollectable 
gc: uncollectable 
gc: uncollectable <_StdcallFuncPtr 015DAE48>
gc: uncollectable 
4

What am I doing wrong?

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


Communication between python scripts

2005-03-01 Thread Chris
Is there a preferred method for having different scripts on different 
computers communicate with each other?

For example, script A could tell script B that it is done with a certain 
process.

I know how to do this using e-mail, but I would like a more direct 
method if possible. If my ISP's mail server goes down, for example, I 
don't want my processes to come to a screeching halt.

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


Relative imports

2005-03-05 Thread Chris
Why do relative imports cause warnings in PyLint?
A warning like this:
ID:W0403  Relative import 'myPythonFileInTheSameFolder'
When the import is like:
from myPythonFileInTheSameFolder import MyClass

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


Re: Relative imports

2005-03-05 Thread Chris
After reading that link I tried to change my imports like this:
" from .myPythonFileInTheSameFolder import MyClass"

Well, this caused an error in PyLint:
Encountered "." at line 1, column 6. Was expecting one of: "or" ...
"and" ... "not" ... "is" ... "in" ... "lambda" ...
   "if" ... "else" ... "elif" ... "while" ... "for" ...
"try" ... "except" ... "def" ... "class" ...
"finally" ... "print" ... "pass" ... "break" ...
"continue" ... "return" ... "yield" ... "import" ...
"from" ... "del" ... "raise" ... "global" ... "exec"
... "assert" ... "as" ...  ...
ID:E0001  invalid syntax

I'm getting more and more confused...
How can I correctly do a relative import ?

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


Re: Web framework

2005-03-10 Thread Chris
In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> Gianluca Sartori wrote:
> > Hi guys,
> >
> > What web framework do you suggest to develop with?
> 
> I really like CherryPy.  It has a very intuitive design.  A "directory"
> is an object and the "files" in it are methods.  URL variables are
> passed as arguments to the methods.  The CherryPy site has a good
> tutorial and some examples that should get you up and running fairly
> quickly.
> 
> http://www.cherrypy.org
> 
> > Thanks for any suggestion,
> > Gianluca
> 
> Hope this helps.
> 
> Christian
> 
> 
Does CherryPy require a python installation on the client side?
-- 
http://mail.python.org/mailman/listinfo/python-list


csv module and unicode, when or workaround?

2005-03-11 Thread Chris
hi,
to convert excel files via csv to xml or whatever I frequently use the 
csv module which is really nice for quick scripts. problem are of course 
non ascii characters like german umlauts, EURO currency symbol etc.

the current csv module cannot handle unicode the docs say, is there any 
workaround or is unicode support planned for the near future? in most 
cases support for characters in iso-8859-1(5) would be ok for my 
purposes but of course full unicode support would be great...

obviously I am not a python pro, i did not even find the py source for 
the module, it seemed to me it is a C based module?. is this also the 
reason for the unicode unawareness?

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


Re: csv module and unicode, when or workaround?

2005-03-12 Thread Chris
hi,
thanks for all replies, I try if I can at least get the work done.
I guess my problem mainly was the rather mindflexing (at least for me) 
coding/decoding of strings...

But I guess it would be really helpful to put the UnicodeReader/Writer 
in the docs

thanks a lot
chris
--
http://mail.python.org/mailman/listinfo/python-list


database questions ala newbie pythonist

2004-12-01 Thread chris
Hello,
  Just started with python and databases.
I am making a small script to update a local database.
Looked around and couldn't find to many links with info about python with
databases.
Any links or other resources anyone can recommend is appreciated.

My question is in the following small script:

##
import dbi
import odbc
myconn = odbc.odbc('testpy')
mycursor = myconn.cursor()
mycursor.execute('Update Categories Set DelStatus = 0 Where ProductID =
1190' )
mycursor.close()
myconn.close()
...
###

This works fine using the literals 0 (For Delstatus) and 1190 (for
ProductID)
But when I try to use a variable such as:

###
...
varA = '0'
varB = '1190'
mycursor.execute('Update Categories Set DelStatus = ' varA 'Where ProductID
= ' varB)
...
###

I get errors.  Please excuse my ignorance in what is probably obvious to
most others within this newsgroup.
What I am trying to do is to update my database from a 2 field .CSV file
I figured I could load the CSV file into a dictionary and parse each row
running a query using the values from varA and VarB from the key value
pairs.
Right now I am just trying to get the database part to work that is why
there is no CSV code.
So I guess what I am asking is how do I pass values through the sql
statement:
###
...
mycursor.execute('Update Categories Set DelStatus = X1 Where ProductID =
X2' )# Values replacing X1 and X2.
...
#######
Any help is greatly appreciated.

Chris


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


a newbie question

2004-12-08 Thread chris
In what directory are the preinstalled python libraries located on a
Linux RH9 machine?

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


Re: Fun with Outlook and MAPI

2004-12-10 Thread Chris
Will McGugan wrote:
I'm trying to send an e-mail through outlook.  So far I've gotten it 
to work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My 
only problem is that when I call Resolve() and Send(), I get 
confirmation dialogs.  I will be sending out quite a few e-mails at a 
time, and would rather not have the user have to click yes for every 
single one.  Does anyone know a workaround?  I know about smtplib, but 
I would prefer to simply make what I have work.  Thanks.
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a service 
pack as an anti-virus measure, so no work-around. Not all clients show 
these anoying dialogs though. Thunderbird definately doesn't.
Unfortunately, I don't have the option of installing Thunderbird.
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: a newbie question

2004-12-11 Thread chris
Thank you. That's exactly what I needed.

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


Re: Fun with Outlook and MAPI

2004-12-13 Thread Chris
At the risk of beating a dead horse, but you really should consider
using SMTP instead if you are really going to be sending a lot
of messages.
The problem is that doesn't work in more complicated configurations
such as when authentication and/or SSL have to happen, not to mention
the issue of configuring servers and ports, that users have already
configured in their mail clients.  Additionally when you use MAPI,
messages that you send also end up in your sent items folder. (I
also have not had any issue sending lots of messages using MAPI).
Ultimately the utility of vanilla of pure SMTP will depend on
customer requirements and how simple the configuration is.
That pretty much sums it up.  Also, since everything is done over IMAP 
with Outlook, I don't really have access to an SMTP server.

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


Re: Fun with Outlook and MAPI

2004-12-13 Thread Chris
There is actually a workaround. You're using Simple MAPI which has a 
nice easy interface. The confirmation dialogs are only for Simple MAPI. 
Using Extended MAPI can work around the problem but its a lot more tricky.
See the initial discussion here: 
http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2160646

This code has now been included in pywin32 somehow but I can't remember 
where and its late. Should also be a cookbook entry. Maybe Google can 
help :-)
Okay, here's the results.  The good news is that the code sent the mail 
without any popup's.  The bad news is that the sent e-mail stays in the 
outbox instead of the sent folder.  Any suggestions?

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


Re: Fun with Outlook and MAPI

2004-12-13 Thread Chris
Okay, here's the results.  The good news is that the code sent the 
mail without any popup's.  The bad news is that the sent e-mail stays 
in the outbox instead of the sent folder.  Any suggestions?
Well, only the same one I've already made, which is to look on the 
win32all mailing list archives. Since this appears to be beyond you, 
here's a note by Chad Stryker commenting on an original work by David 
Fraser.

It may give you the clues you need, otherwise Google for the whole 
thread(s).

"""Thank you for figuring this extended MAPI interface all out.  I 
discovered a couple of problems with the code (on my system at least). 
First, the message in my outbox was marked as read.  Second, the message 
would remain in the outbox after it was sent.  After several hours of 
work, I added three lines to the function that mark the message as 
unread and cause the message to be deleted from the outbox after it is 
sent.

First, I added a constant that I found in the MAPI header file MAPIDefS.h.
CLEAR_READ_FLAG = 4
Next I added two lines just before “outboxfolder.SaveChanges(0)”.
message.SetReadFlag(CLEAR_READ_FLAG)
message.SetProps([(mapitags.PR_DELETE_AFTER_SUBMIT,1)])
With these changes, the behavior in the outbox is consistent with 
sending messages directly from Outlook.
"""

regards
 Steve
Actually, I had already found that message.  It still doesn't do what 
I'm looking for(namely moving sent messages to the Sent folder).

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


Re: Python IDE

2004-12-14 Thread Chris
What IDE's do y'all recommend for Python?  I'm using PythonWin atm, 
but I'd like something with more functionality.
Oh god we're all going to die.
-chuckle-  Hopefully I don't start off a full fledged war.-grin-
But er, ActiveState Komodo is quite nice IIRC (can't use it anymore as 
all my coding is commercial and I don't need it enough to spend that 
much cash on it) but EditPlus is nice once you get it setup but not very 
IDEy. Eclipse with one of the various Python modules is horrible don't 
bother. There is of course always Emacs, but again it's hardly Visual 
Studio (im only talking about the UI, emacs fans please dont flame me)

Personally my vote goes for Komodo, it's at least worth a try with a 
personal liscense.
Why didn't you like Eclipse?  Was it that the Python modules were bad, 
or just Eclipse in general?  I use it for my Java developement and 
haven't had any problems with it.

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


Re: Python 3.0

2004-12-14 Thread Chris
Okay, color me stupid, but what is everyone referencing when they mention Python 3.0?  I didn't 
see any mention of it on the Python site.
http://www.python.org/peps/pep-3000.html
(which happens to be the first hit if you search for "python 3.0" in the
search box on python.org...)
Okay, I feel dumb now. :)
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Python IDE

2004-12-14 Thread Chris
What IDE's do y'all recommend for Python?  I'm using PythonWin atm, but 
I'd like something with more functionality.

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


Re: Python IDE

2004-12-15 Thread Chris
Try WingIDE if you have some money (about 35 E/$ for the personal
version) to spend, it's worth every (euro)cent. But please try SPE
first, maybe that's enough for you.
SPE?
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: datetime

2004-12-16 Thread Chris
Okay, I searched www.python.org for a date handler and found datetime. 
http://www.python.org/dev/doc/devel/lib/module-datetime.html  However, 
whenever I try to import datetime, I get a No module named datetime 
error.  What am I missing?
The module documentation says "New in version 2.3".
Is that what you're running ?
Doh!  No, I'm still running 2.2.  Anyways, I managed to do what I needed 
using time.  Thanks for the help, though.

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


Fun with Outlook and MAPI

2004-12-10 Thread Chris
I'm trying to send an e-mail through outlook.  So far I've gotten it to 
work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My only 
problem is that when I call Resolve() and Send(), I get confirmation 
dialogs.  I will be sending out quite a few e-mails at a time, and would 
rather not have the user have to click yes for every single one.  Does 
anyone know a workaround?  I know about smtplib, but I would prefer to 
simply make what I have work.  Thanks.

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


Re: Fun with Outlook and MAPI

2004-12-10 Thread Chris
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a 
service pack as an anti-virus measure, so no work-around. Not all 
clients show these anoying dialogs though. Thunderbird definately 
doesn't.
There is actually a workaround. You're using Simple MAPI which has a 
nice easy interface. The confirmation dialogs are only for Simple MAPI. 
Using Extended MAPI can work around the problem but its a lot more tricky.
See the initial discussion here: 
http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2160646

This code has now been included in pywin32 somehow but I can't remember 
where and its late. Should also be a cookbook entry. Maybe Google can 
help :-)
Cool.  I'll take a look an' see if I can get it to work.  MAPI has 
turned out to be a major PITA.  Especially when trying to learn it and 
Python at the same time. :)

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


Python 3.0

2004-12-14 Thread Chris
Okay, color me stupid, but what is everyone referencing when they 
mention Python 3.0?  I didn't see any mention of it on the Python site.

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


PythonWin Not Updating

2004-12-14 Thread Chris
I'm working on a program in PythonWin.  The problem I'm running into is 
that after I make a code change, PythonWin doesn't always see it.  Has 
anyone else had this problem?

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


datetime

2004-12-16 Thread Chris
Okay, I searched www.python.org for a date handler and found datetime. 
http://www.python.org/dev/doc/devel/lib/module-datetime.html  However, 
whenever I try to import datetime, I get a No module named datetime 
error.  What am I missing?

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


Use macros in Excel via win32com

2004-12-18 Thread chris
I'm creating an excel document dynamically from scratch using Python
and the win32com module.  All is well, but now I need to add a macro to
the spreadsheet and run it (to enable some sorting features in the
spreadsheet).  I think I know how to run a macro once it's installed
(using the Run method of the excel application object...I think), but I
can't figure out how to "install" the VBA macro code into the
spreadsheet to begin with from my Python script.
Any tips appreciated.

Thanks,
Chris

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


odbc script

2004-12-18 Thread Chris
Hello,
  I posted a while back about a newbie database question and got a 
lot of great help here.  My script that I am creating has come a long way 
(For me!) and almost does what I need it too.  I am basicly using a 
dictionary to update a access database using an odbc connector.  I am able 
to connect and it seems that I am able to loop through the code to update 
all the rows I need to.  The one weird bug I seem to get is what ever is the 
last loop through doesn't seem to update the database?
Here is my code:
**
import dbi
import odbc
invdictionary = {1112:0 ,:0 ,1129:0 ,1139:1 ,1149:1 ,1159:0 ,1169:0 
,1179:0 ,1189:1 ,1199:0} # ( key : value )
invd = invdictionary.items() # convert to a list to loop 
through
myconn = odbc.odbc('testpy')# connect to database
mycursor = myconn.cursor()
for x in invd:
mycursor.execute('Update Categories Set StockStatus=? Where ProductID=? 
;',(x[1], x[0]))# run my sql update
print x[0], x[1]   # Just to help me 
debug
mycursor.close()
myconn.close()
print invdictionary  # Just to help me debug
print invd   # Just to help me 
debug

Here is the output:
*
1189 1
1159 0
1129 0
1199 0
1169 0
1139 1
 0
1112 0
1179 0
1149 1
{1189: 1, 1159: 0, 1129: 0, 1199: 0, 1169: 0, 1139: 1, : 0, 1112: 0, 
1179: 0, 1149: 1}
[(1189, 1), (1159, 0), (1129, 0), (1199, 0), (1169, 0), (1139, 1), (, 
0), (1112, 0), (1179, 0), (1149, 1)]

After I run this script All the values update correctly except the 1149 
value which never changes in the database.
I messed with this for a while and found by adding items to the dictionary 
that it never seems to update whatever is the last item to go through the 
loop.
I thought I would float it on here and see if this isn't an obvious mistake 
that I just can't see.  Any help is appreciated.


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


Re: Use macros in Excel via win32com

2004-12-18 Thread chris
Thanks, but the problem is that I need to create the entire Excel
document from scratch, dynamically, via the Python script.  I want the
script to add the macro code.

-Chris

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


Re: Use macros in Excel via win32com

2004-12-20 Thread chris
This makes sense.  Thanks for the ideas.

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


Re: Python To Send Emails Via Outlook Express

2004-12-20 Thread Chris
I'm a newbie (oh no I can here you say another one...)
How can I get Python to send emails using the default windows email
client (eg outlook express)?
I thought I could just do the following
import win32com.client
s = win32com.client.Dispatch('CDO.Message')
s.From = "[EMAIL PROTECTED]"
s.To = "[EMAIL PROTECTED]"
s.Subject = "The subject"
s.Send
... but nothing happens.
What am I doing wrong? Does anyone have some sample code to share with
me please?
Do a search on the list for the thread Fun with Outlook and MAPI. 
That'll have your answers.

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


Re: odbc script

2004-12-20 Thread Chris
Thanks Benji,
  I took your advice and added in the conn.commit() into 
the script but still had the same problem.  I did some digging around the 
odbc documentation and found this bug:
**
4. Hirendra Hindocha also reports: inserting a single row into a table 
doesn't work properly unless one specifically deallocates the cursor.
for example the following code snippet -
conn = odbc.odbc(str)
cur = conn.cursor()
sql = 'insert into abc_table values(1,2,'abc')
cur.execute(sql)
conn.commit()
cur.close()
conn.close()doesn't work, unless you add the following lines

cur = None
conn = None at the end of the above code snippet. Tracing with ODBC and a 
look into odbc.cpp shows that sqlfreestmt is not being called until the 
explicit deallocation is done. [Note however, Bill Tutt seems to think that 
this problem implies a problem with the specific ODBC driver, rather than 
with the ODBC implementation of Python. I haven't a clue!]

*
I figured what the heck and added in the 2 lines specified:
cur = None
conn = None
and sure enough it worked after that!  I am not sure why but figure that 
when the last loop goes through it is as if it is updating 1 single row?
Either way it works now.  Thanks for the help as I am sure I needed the 
conn.commit() as well.

Chris

"Benji York" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Chris wrote:
>> what ever is the last loop through doesn't seem to update the
>> database?
>
> Try a conn.commit() after your loop.
> --
> Benji York 


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


Are tuple really immutable?

2004-12-26 Thread Chris
Hi

Consider the following tuples:
>>> t = ([1],[2])
>>> u = (1,2)
>>> v = ('1','2')
>>> t
([1], [2])
>>> u
(1, 2)
>>> v
('1', '2')
>>> t.__hash__()
Traceback (most recent call last):
File "", line 1, in ?
TypeError: list objects are unhashable
>>> u.__hash__()
219750523
>>> v.__hash__()
-1786881095
>>> d = dict()
>>> d[t] = 't'
Traceback (most recent call last):
File "", line 1, in ?
TypeError: list objects are unhashable
>>> d[u] = 'u'
>>> d[v] = 'v'
>>> d
{('1', '2'): 'v', (1, 2): 'u'}

t, u and v are all tuples. t and v elements are sequences.
Yet, t cannot be a dictionnary key because its elements are mutable.

1) Given a tuple, how can I know if it can be a dictionnary key or not?

Of course I could call __hash__ and catch for a TypeError exception,
but I'm  looking for a better way to do it.

2) Would it be possible to have a "ismutable" function or method? Like:
>>> t.ismutable()
True, well maybe not...
>>> u.ismutable()
False
>>> u.ismutable()
False

3) In this example, is t considered mutable or not?
"Tuple are immutable" says the doc, but:
>>> t[0].append(0)
>>> t
([1, 0], [2])

The tuple is immutable but its elements can be mutable: I tend to think
that it means that the tuple is mutable. Indeed, it changed!

4) Even more confusing: I had the following strange result:
(with both Python 2.3.3 and 2.4)
>>> t[0]+=[1]
Traceback (most recent call last):
File "", line 1, in ?
TypeError: object doesn't support item assignment
>>> t
([1, 0, 1], [2])
There was an exception, but the list was still changed!?

Chris

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


Re: Are tuple really immutable?

2004-12-28 Thread Chris
Thank you.

Chris

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


Re: Are tuple really immutable?

2004-12-29 Thread Chris
I'm suing Google Groups (beta) which has a treeview and my thanks were
a reply to Fredrik Lundh. In fact I simply clicked a "reply" link below
his post.
Of course you all helped me to better understand the
"mutable/immutable" concept but Fredrik Lundh deserves more thanks
since he replied to all my questions ;-)

Chris

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


EARN CASH BY READING EMAILS. THIS REALLY WORKS I ALLREADY HAVE 10€ IN 1 MONTH AND ITS GROWING FASTER AND FASTER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

2005-03-27 Thread CHRIS
http://www.smsprofit.nl/aanmeld.php?ref=78267




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


suggestions on how to do this

2005-04-27 Thread chris
The problem I have is as follows:

I have a recursive function b(k)

b(k) = -(A/k**2)*(b(k-2) - b(k-5))
k<0, b(k)=0
k=0, b(k)=1
k=1, b(k)=0

eg. b(2) = -A/4
  b(3) = 0
  b(4) = A**2/64

note that as k increases b(k) can itself be a sum of terms in powers of A
rather than a single power of A in the examples above.

Summing all terms and equating to zero gives:

F= sum b(k) = 0 for all k = 0, infinity

When this is expanded I get a polynomial F(A). I want to determine the
coefficients of the polynomial so that I can find the roots of the function
F up to a specified order of A.


I have yet to code this but I was hoping for some ideas on how to do this
reasonably.

I figure I can compute each b(k) and store the numeric value(s) and
associated powers of A. Then collect coefficients for like powers of A.
Finally I have a set of polynomial coefficients in A which I can pass to
scipy.base.roots()

Any suggestions on how I might do this efficiently? I have no doubt I can
get this done with brute force, but I would prefer to explore more elegant
means which I look to the masters for.

tia



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


SWIG char** to Python list

2005-04-29 Thread Chris
Hi

I have a C function that builds a list of null terminated strings:
void buildStringList(char **asStrings, int n);
The number of elements in the list is given in input.

I'd like to have this function available in Python.
I use SWIG but I'm a complete newbie with it.
I've only found an example to convert a Python list to C char**
http://www.swig.org/Doc1.3/Python.html#Python_nn59

I naively replaced typemap(in) by typemap(out) but it doesn't work :
TypeError: argument number 1: a 'char **' is expected, 'list([])' is
received

Do I have to learn more of SWIG or is there a simple way to make my C
function fill a list of Python objects?

Regards
Chris


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


socket client and server in one application?

2014-05-05 Thread chris
I have a python script that uses a serial port to read data from an xbee radio 
and it delivers the data to a socket server.

Now I need to retrieve the data from a socket client so I can send data out on 
the common serial port.

I think I need a combination of threads, queues, socket client and sever.

Anyone have ideas about how I might frame this out?

Thanks in advance,
Chris.


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


Re: socket client and server in one application?

2014-05-05 Thread chris
Thanks to Marko, Chin, Grant.

There's a lot to study, asincio, urllib, threads, select/poll.

I'm using a dispatch method to receive and occasionally send data through a 
serial port on a Raspberry Pi.  I think the dispatch method is essentially a 
threaded approach, right?

Now to receive serial data and send via socket, then occasionally receive some 
socket based input and send out on the same serial port.  It's combining the 
client and server socket code into a single app (so I can have a single 
connection to the serial port) that has me confused.  I don't see any 
discussion of that anywhere.

Thanks so much,
Chris.
-- 
https://mail.python.org/mailman/listinfo/python-list


IndexError: pop from empty list

2014-05-15 Thread chris
Any ideas about what this might mean?

Running Debian Wheezy on a RaspBerry Pi and collecting data on a dispatch 
thread that is reading input on the serial port (connected to xbee series 1).

It happens every few days but it really chokes the program.

Thanks for any tips,
ChrisJ




Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
  File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 95, in run
self._callback(self.wait_read_frame())
  File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in 
wait_read_frame
return self._split_response(frame.data)
  File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 288, in 
_split_response
info[parse_rule[0]] = parse_rule[1](self, info)
  File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in 

lambda xbee,original: xbee._parse_samples(original['samples'])
  File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in 
_parse_samples
digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0))
IndexError: pop from empty list


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


Re: socket client and server in one application?

2014-05-15 Thread chris
Thank you all.

The 2 threaded in/out sockets are working great.  I'm receiving input on the 
xbee/serial port  in the dispatch thread.  For each receipt I send the xbee 
data through a socket connected to node-red.  Node-red is collecting the data, 
parsing it and sending it along to other end points; mainly to carbon/graphite 
for charting.

Then I've got some injection nodes in node-red that can send signals back to 
the python script.  The python script has a socket server in the main loop that 
waits for a specialized command which, when received, sends a command back out 
the serial/xbee port to instruct a device to turn on/off.

Generally it works great but I'm tuning it to optimize the amount of data I'm 
managing.  The xbees are set to send 4 data points every .5 seconds.  I only 
have 5 xbee radios in my setup but I think that means the little raspi is 
collecting up to 40 data points every second.

On the node-red, it breaks each data set into 4 discreet entries and sends 
those to the carbon/graphite charting app.

I'm thinking of including some signal averaging into the python receiver to 
smooth out the various signals I'm tracking.

Again, thank you all for your help,
Chris.



On Monday, May 5, 2014 4:05:22 PM UTC-7, Chris Angelico wrote:
> On Tue, May 6, 2014 at 8:37 AM,   wrote:
> 
> > I'm using a dispatch method to receive and occasionally send data through a 
> > serial port on a Raspberry Pi.  I think the dispatch method is essentially 
> > a threaded approach, right?
> 
> >
> 
> > Now to receive serial data and send via socket, then occasionally receive 
> > some socket based input and send out on the same serial port.  It's 
> > combining the client and server socket code into a single app (so I can 
> > have a single connection to the serial port) that has me confused.  I don't 
> > see any discussion of that anywhere.
> 
> >
> 
> 
> 
> Threads would be easy. As I understand it, you have two bidirectional
> 
> connections, and you're simply linking them? Sounds like a very simple
> 
> proxy/tunnel. You don't need to multiplex, so all you need is two
> 
> threads: one reading from the socket and writing to the serial port,
> 
> and one reading from the serial port and writing to the socket. The
> 
> code would look something like this:
> 
> 
> 
> serial_port = open(...)
> 
> tcp_socket = socket.create_connection(...)
> 
> # initialize them both, do whatever setup is needed
> 
> 
> 
> def socket_to_serial():
> 
> while True:
> 
> data = tcp_socket.recv(4096)
> 
> serial_port.write(data)
> 
> 
> 
> Thread.Thread(target=socket_to_serial).start()
> 
> 
> 
> while True:
> 
> data = serial_port.read(4096)
> 
> tcp_socket.send(data)
> 
> 
> 
> 
> 
> Two simple loops, running concurrently. Pretty straight-forward as
> 
> threads. Both of them will fall idle in their read/recv calls, so
> 
> threading works very nicely here.
> 
> 
> 
> ChrisA

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


Re: IndexError: pop from empty list

2014-05-15 Thread chris
No, that was pretty much what I was looking for.  If anyone has an answer to 
the deeper question, that would be icing on the cake.

What is interesting is that usually the traceback shows the line of code that I 
invoke which, deep inside a library I'm using, has generated an error.  In this 
case I don't know which of my commands has spawned the error.

I can experiment, I suppose, with putting a try/catch around suspected lines of 
code...

Thanks,
Chris.


On Thursday, May 15, 2014 9:48:00 PM UTC-7, Gary Herron wrote:
> On 05/15/2014 09:36 PM, [email protected] wrote:
> 
> > Any ideas about what this might mean?
> 
> >
> 
> > Running Debian Wheezy on a RaspBerry Pi and collecting data on a dispatch 
> > thread that is reading input on the serial port (connected to xbee series 
> > 1).
> 
> >
> 
> > It happens every few days but it really chokes the program.
> 
> >
> 
> > Thanks for any tips,
> 
> > ChrisJ
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > Exception in thread Thread-2:
> 
> > Traceback (most recent call last):
> 
> >File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
> 
> >  self.run()
> 
> >File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 95, in 
> > run
> 
> >  self._callback(self.wait_read_frame())
> 
> >File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in 
> > wait_read_frame
> 
> >  return self._split_response(frame.data)
> 
> >File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 288, in 
> > _split_response
> 
> >  info[parse_rule[0]] = parse_rule[1](self, info)
> 
> >File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in 
> > 
> 
> >  lambda xbee,original: xbee._parse_samples(original['samples'])
> 
> >File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in 
> > _parse_samples
> 
> >  digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0))
> 
> > IndexError: pop from empty list
> 
> 
> 
> The error means that sample_bytes is an empty list so calling pop is an 
> 
> error.
> 
> 
> 
> Or were you asking something deeper, like *why*  sample_bytes is an 
> 
> empty list?
> 
> 
> 
> Gary Herron
-- 
https://mail.python.org/mailman/listinfo/python-list


WSGI (was: Re: Python CGI)

2014-05-25 Thread Chris
On 05/20/2014 03:52 AM, Tim Chase wrote:
> While Burak addressed your (Fast-)CGI issues, once you have a
> test-script successfully giving you output, you can use the
> standard-library's getpass.getuser() function to tell who your script
> is running as.

LoadModule wsgi_module modules/mod_wsgi.so
AddHandler wsgi-script .wsgi
WSGIDaemonProcess myproj user=chris threads=3

[root@t-centos1 ~]# ps -ef|grep chris
chris 1201  1199  0 08:47 ?00:00:00 /usr/sbin/httpd

---8<---
#!/usr/bin/python
import getpass
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
output += getpass.getuser()
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]
--->8---

Hello World!root

Hmm, why is it root?

I'm using Apache and mod_userdir. Can I define WSGIDaemonProcess for
each user?

- Chris

-- 
Gruß,
Christian
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: WSGI

2014-05-25 Thread Chris
On 05/25/2014 12:04 PM, alister wrote:
> is your apache server running as root?
> if so it probably should be corrected

One is running as chris, the others as apache:

[root@t-centos1 ~]# ps -ef|grep httpd
root  1199 1  0 08:47 ?00:00:01 /usr/sbin/httpd
chris 1293  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
apache1294  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
apache1295  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
apache1296  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
apache1297  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
apache1298  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
apache1299  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
apache1300  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
apache1301  1199  0 09:47 ?00:00:00 /usr/sbin/httpd
root  1578  1566  0 14:21 pts/000:00:00 grep httpd


-- 
Gruß,
Christian
-- 
https://mail.python.org/mailman/listinfo/python-list


Script suddenly stops

2014-05-29 Thread Chris
Dear All,

I'm trying to read ten 200 MB textfiles into a MySQL MyISAM database
(Linux, ext4). The script output is suddenly stopping, while the Python
process is still running (or should I say sleeping?). It's not in top,
but in ps visible.

Why is it stopping? Is there a way to make it continue, without calling
"kill -9", deleting the processed lines and starting it again?

Thank you in advance.



[1] http://pastebin.com/CxHCA9eB

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


Re: Script suddenly stops

2014-05-31 Thread Chris
Dear All,

thanks a lot for your replies.

I've found my mistake. The script output stopped, but the script was
still filling the MySQL table. When I resized the Gnome terminal window
the output continued.

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


Re: Introdution

2014-06-02 Thread Chris
Hi,

On 06/03/2014 12:01 AM, Hisham Mughal wrote:
> plz tell me about books for python
> i am beginner of this lang..

the most important commands are in A Byte of Python [1]. This eBook
isn't sufficient for programming, but it's a nice introduction.

I bought Learning Python from Mark Lutz. It's not bad, but I think it's
a bit too narrative.


[1] http://www.swaroopch.com/notes/python/

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


question about dictionaries

2006-01-19 Thread Chris
When you declare a dictionary, Python puts it in a different order than
the way you declare it:

>>> stuff = {'\n':'', ':'\n'}
>>> print stuff
{'':'\n', '\n':''}

Is there a way to stop this behavior? I want to process this dictionary
in the order it's in, element by element. I'm running Python 2.3, if
that helps.   

Thanks for any help!

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


saxutils.XMLGenerator and CDATA

2006-01-20 Thread chris
Confused somewhat xml newbie.  I'm trying to output xml with a CDATA
section, using saxutils.XMLGenerator, but the output contains escaped
'<' and '>'  and '&' from the CDATA element.  Shouldn't it be spit out
intact?

Here's code and output:

from xml.sax import saxutils
import sys
handler = saxutils.XMLGenerator(sys.stdout)
handler.startDocument()
handler.startElement('sometag', {})
handler.characters('')
handler.endElement('sometag')
handler.endDocument()

Produces:

<![CDATA[x&<>xxx]]>

I was expecting to see



What am I doing wrong here?

Thanks,
Chris

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


Re: How to generate graphics dynamically on the web using Python CGI script?

2006-01-20 Thread chris
This is a cool product that can produce any number of types of graphs.
Supports Python, as well as lots of other languages.  I have used it
with success.  There is a free version, as long as you don't mind the
tiny logo they put into each graph.

http://www.advsofteng.com/

-Chris

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


super quick question

2006-08-04 Thread Chris
is there a prettier way to do this? 
string[:len(string)-1]

thanks!

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


Re: super quick question

2006-08-04 Thread Chris
It's very beautiful. Thanks
jwoolard wrote:
> Chris wrote:
> > is there a prettier way to do this?
> > string[:len(string)-1]
> >
> > thanks!
>
> string[:-1]
>
> Negative indices count from the end of the string! beautiful isn't it?

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


error handling

2006-08-10 Thread Chris
I want to handle errors for a program i'm building in a specific way,
but I don't want to use try/except/finally because it requires forming
new blocks of code. I want to be able things like this:

a = [2, 423, "brownie", 234.34]
try: a[890]
except IndexError: # I don't use 'finally' here because I specifically
want to check for an IndexError
 sys.exit("That number is way too big!")

But sometimes you can have too many of these statements in your
program, and it starts to get tangled and nasty looking. Is there a way
I can modify sys.error so that when the interpreter comes accross an
IndexError it prints "That number is way too big!" before it exits?

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


Re: error handling

2006-08-10 Thread Chris
I want to do this because there are several spots in my program where
an error might occur that I want to handle the same way, but I don't
want to rewrite the try..except block again. Is that clearer?

And I meant sys.stderr... sorry 'bout that

Simon Forman wrote:
> Chris wrote:
> > I want to handle errors for a program i'm building in a specific way,
> > but I don't want to use try/except/finally because it requires forming
> > new blocks of code. I want to be able things like this:
> >
> > a = [2, 423, "brownie", 234.34]
> > try: a[890]
> > except IndexError: # I don't use 'finally' here because I specifically
> > want to check for an IndexError
> >  sys.exit("That number is way too big!")
> >
> > But sometimes you can have too many of these statements in your
> > program, and it starts to get tangled and nasty looking. Is there a way
> > I can modify sys.error so that when the interpreter comes accross an
> > IndexError it prints "That number is way too big!" before it exits?
>
> You don't want to do what because why?  Huh?
>
> I'm sorry man, I don't want to be harsh, but use try..except blocks.
>
> If your code is getting "tangled and nasty looking" you probably need
> to break it up into small[er] functions, or redesign it somehow.
>
> Peace,
> ~Simon
>
> (Also, there's no such thing as sys.error, do you mean
> sys.excepthook()?)

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


dictionary update

2006-08-15 Thread Chris
I have a instance attribute self.xds and a local variable xds in the 
instance . Both are dictionaries. I understand that I can update 
self.xds with xds as follows: self.xds.update(xds)

However I have many instance attributes, self.i, and local variables i.
I'd like to be able to do this:

for i in list_of_i's:
 self.i.update(i)

How can this be done (I'm assuming it can be).

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


Re: Creating Charts in Excel with pyExcelerator.ExcelMagic

2006-08-16 Thread Chris
implicate_order wrote:
> Greetings,
> 
Here's an Excel class I use. I'm afraid I can't recall where I found the
basic class. I have a vague recollection it is due to Mark Hammond,
author of the win32com package. Might have been in win32com demos. 
(Whoever the original author is anyway, many thanks). I added a few 
methods, including XY plotting (you can probably tell by the change in 
coding style to that of a newb). Not very generic but you may find it 
useful, as the hardest part I found was discovering what the Excel 
specific methods etc where. The MSDN developer site for Excel is a big 
help. http://msdn.microsoft.com/developercenters/



import win32com.client
from win32com.client import Dispatch, constants

class ExcelWorkbook:
 """ An Excel workbook object"""
 def __init__(self, filename=None):
 # Use these commands in Python code to auto generate .py 
support for excel
 from win32com.client import gencache
 gencache.EnsureModule('{00020813---C000-0046}', 
0, 1, 4)
 # start excel
 self.xlApp = Dispatch('Excel.Application')

 if filename and os.path.exists(filename):
 self.xlBook = self.xlApp.Workbooks.Open(filename)
 else:
 self.xlBook = self.xlApp.Workbooks.Add()
 self.filename = filename

 def save(self, newfilename=None):
 if newfilename:
 self.filename = newfilename
 self.xlBook.SaveAs(newfilename)
 else:
 self.xlBook.Save()

 def close(self):
 self.xlBook.Close(SaveChanges=0)
 del self.xlApp

 def show(self):
 self.xlApp.Visible = 1

 def hide(self):
 self.xlApp.Visible = 0
 def newSheet(self, sheet):
 try:# fails if sheet already exists
 self.xlBook.Sheets(sheet).Name == sheet
 except:
 self.xlSheet = self.xlBook.Worksheets.Add()
 self.xlSheet.Name = sheet

 def deleteSheet(self, sheet):
 try:# ignore if sheet doesn't exist
 self.xlBook.Sheets(sheet).Delete()
 except:
 pass

 def selectSheet(self, sheet):
 self.xlBook.Worksheets(sheet).Select()

 def getCell(self, sheet, row, col):
 "Get value of one cell"
 sht = self.xlBook.Worksheets(sheet)
 return sht.Cells(row, col).Value

 def setCell(self, sheet, row, col, value):
 "set value of one cell"
 sht = self.xlBook.Worksheets(sheet)
 sht.Cells(row, col).Value = value

 def getRange(self, sheet, row1, col1, row2, col2):
 "return a 2d array (i.e. tuple of tuples)"
 sht = self.xlBook.Worksheets(sheet)
 return sht.Range(sht.Cells(row1, col1), sht.Cells(row2, 
col2)).Value

 def setRange(self, sheet, topRow, leftCol, data):
 """insert a 2d array starting at given location.
 Works out the size needed for itself"""
 bottomRow = topRow + len(data) - 1
 rightCol = leftCol + len(data[0]) - 1
 sht = self.xlBook.Worksheets(sheet)
 sht.Range(
 sht.Cells(topRow, leftCol),
 sht.Cells(bottomRow, rightCol)
 ).Value = data

 def getContiguousRange(self, sheet, row, col):
 """Tracks down and across from top left cell until it
 encounters blank cells; returns the non-blank range.
 Looks at first row and column; blanks at bottom or right
 are OK and return None witin the array"""

 sht = self.xlBook.Worksheets(sheet)

 # find the bottom row
 bottom = row
 while sht.Cells(bottom + 1, col).Value not in [None, '']:
 bottom = bottom + 1

 # right column
 right = col
 while sht.Cells(row, right + 1).Value not in [None, '']:
 right = right + 1

 return sht.Range(sht.Cells(row, col), sht.Cells(bottom, 
right)).Value

 def fixStringsAndDates(self, aMatrix):
 # converts all unicode strings and times
 newmatrix = []
 for row in aMatrix:
 newrow = []
 for cell in row:
 if type(cell) is UnicodeType:
 newrow.append(str(cell))
 elif type(cell) is TimeType:
 newrow.append(int(cell))
 else:
 newrow.append(cell)
 newmatrix.append(tuple(newrow))
 return newmatrix

 def convertRCToA1(self, R1C1):
 """
 fromReferenceStyle  =   constants.xlR1C1,
 toReferenceStyle=   constants.xlA1,
 toabsolute  =   constants.xlRelative)
 """
 return self.xlApp.ConvertFormula(R1C1, constants.xlR1C1,
 constants.xlA1, 
constants.xlRelative)

 def insertFormulaInRange(self, sheet, row, col, len, formula):
 self.selectSheet(sheet)
 sht = self.xlBook.Worksheets(sheet)
 sht.

  1   2   3   4   5   6   7   8   9   10   >