possible to run a python script without installing python?

2011-03-15 Thread davidj411
it seems that if I copy the python.exe binary and the folders
associated with it to a server without python, i can run python.
does anyone know which files are important to copy and which can be
omitted?

i know about py2exe and have had no luck with it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AIX installation can't find zlib

2011-11-03 Thread davidj411
we using RPM to install python 2.7.x and same issue there, can't import gzip 
b/c zlib is missing. we used RPM to install zlib, but did not effect python.
you mentioned modules and uncommenting something. could you be more specific? 
also , we are not compiling. would that be required for python after 
uncommenting zlib?
-- 
http://mail.python.org/mailman/listinfo/python-list


convert string number to real number - ValueError: invalid literal for int() with base 10: '"2"'

2008-02-28 Thread davidj411
i am parsing a cell phone bill to get a list of all numbers and the
total talktime spend on each number.

i already have a unique list of the phone numbers.
now i must go through the list of numbers and add up the totals for
each number.
on the bill, each line has a few fields,one field containing the phone
number, another field containing the number of minutes on that call.
the bill is comma delimited.

here is the function i wrote to get one number at a time's total
talktime.

def getsinglenumbertalktime(number,talktime):
for line in file[0:-2]:
 if number in line:
li=line.split(',')
if len(li)==6 and li[5]!="Minutes" :
print "talktime type: " + str(type (talktime))
#li[5]=fpformat.fix(li[5],0)

print li[5] + "li[5] type: " + str(type(li[5]))
newvar = int(li[5])
print (type(newvar))
print li[5]
talktime = talktime + li[5]
return talktime

here is the output with error that i get back.

talktime type: 
"2"li[5] type: 
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\path\inprog\all_t_mob_nums.py", line 74, in 
getsinglenumbertalktime('"800-218-2644"',talktime)
  File "c:\path\inprog\all_t_mob_nums.py", line 66, in
getsinglenumbertalktime
newvar = int(li[5])
ValueError: invalid literal for int() with base 10: '"2"'


here is the question:

How can i convert a string number like "2" to a true number that can
be added.
I have tried using pfformat, float(), and int() - all with no good
results.
this seems like is should be simple, but it just plain isn't.


I actually found a good solution.
basically, take each entry and add it to a list.
then iterate through the list , converting each item to int().
then add them to sum them all up.

FINAL SOLUTION:
def getsinglenumbertalktime(number,talktime):
num_of_calls=0
num_mins=[]
for line in file[0:-2]:
#print "LINE: " + line
#print number in line
if number in line:
num_of_calls +=  1
#print number,num_of_calls
li=line.strip("\n")
#print "stripped:" + line
li=li.split(',')
#print "split: " + str(li)
#print "len of li: " + str(len(li)) + str(num_of_calls)
if len(li)==7 and li[5]!="Minutes" :
#print "talktime type: " + str(type (talktime))
#print li[4] + "li[4] type: " + str(type(li[5]))
#newvar = fpformat.fix(li[4],0)
#print (type(newvar))
#print "len 7: " + str(type(li[6]))
num_mins.append(li[6])
#talktime = talktime + int(a)

if len(li)==6 and li[5]!="Minutes" :
#print "talktime type: " + str(type (talktime))
#print li[5] + "li[5] type: " + str(type(li[5]))
#newvar = fpformat.fix(li[4],0)
#print (type(newvar))
#print "len 6: " + str(type(li[5]))
num_mins.append(li[5])
#talktime = talktime + int(a)
#return talktime , num_of_calls
x=0
#print "this" + str(number) + str(num_mins)
for a in num_mins:
b=int(a)
x=x+b
print str(number), str(x), str(type(x))

output should look like this (parts of script are not included)
555-555- replaced the innocent :P):
555-555- 19 
555-555- 6 
555-555- 3 
555-555- 3 
555-555- 2 
555-555- 52 
-- 
http://mail.python.org/mailman/listinfo/python-list


change user-agent

2008-03-05 Thread davidj411
I came across this post on the net and wanted to know what was meant
by down-level module.

So, how can we change the User-Agent? If we don't want to change the
headers using a lower-level module such as httplib, the solution is
quite easy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: documenting formal operational semantics of Python

2008-03-05 Thread davidj411
Python 3.0 might end up better, but converting all those scripts will
be a chore.
I'd be curious to know how that will be done.
-- 
http://mail.python.org/mailman/listinfo/python-list


lowercase u before string in "python for windows"

2008-03-10 Thread davidj411
why does this occur when using the python windows extensions? all
string are prefixed by a lowercase "u".
is there a newsgroup explicitly for python windows extensions?

example of output below.

SMBIOSBIOSVersion:u'A16'
SMBIOSMajorVersion:2
SMBIOSMinorVersion:3
SMBIOSPresent:True
SoftwareElementID:u'Phoenix ROM BIOS PLUS Version 1.10 A16'
SoftwareElementState:3
Status:u'OK'
TargetOperatingSystem:0


here is a snippet of the code:

if objItem.Status != None:
print "Status:" + ` objItem.Status`
if objItem.TargetOperatingSystem != None:
print "TargetOperatingSystem:" + `
objItem.TargetOperatingSystem`
if objItem.Version != None:
print "Version:" + ` objItem.Version`
-- 
http://mail.python.org/mailman/listinfo/python-list


difference b/t dictionary{} and anydbm - they seem the same

2008-03-11 Thread davidj411
anydbm and dictionary{} seem like they both have a single key and key
value.
Can't you put more information into a DBM file or link tables? I just
don't see the benefit except for the persistent storage.

d= dbm.open('c:\\temp\\mydb.dat','n')

It has the following interface (key and data are strings):

d[key] = data   # store data at key (may override data at
# existing key)
data = d[key]   # retrieve data at key (raise KeyError if no
# such key)
del d[key]  # delete data stored at key (raises KeyError
# if no such key)
flag = key in d   # true if the key exists
list = d.keys() # return a list of all existing keys (slow!)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: difference b/t dictionary{} and anydbm - they seem the same

2008-03-11 Thread davidj411

> Persistent storage /is/ the benefit. If you want to store relational
> data, you should use a relational database.

Thanks, that makes sense. Are there any local relational databases
available to python that don't require a server backend?
-- 
http://mail.python.org/mailman/listinfo/python-list


asp versus cgi

2008-11-26 Thread davidj411
when i use cgi, i never get a 500 error but i can see how it might
take on overhead if many users are hitting the site at once. so to
avoid this, i looked into registering the python engine for ASP
requests.

when i use asp (C:\WINDOWS\system32\inetsrv\asp.dll fileversion
info:"--a-- W32i   DLL ENU   5.1.2600.5512 shp369,664 04-14-2008
asp.dll") , i get intermittent results. it either works or generates a
500 error. the error pattern is 200, 500, 200, 500, 200, 500 and so
on.


this is the ASP code when using GET method:

<%@ LANGUAGE = Python%>

<%
import sys
sys.stdout=sys.stdin
usr = Request.QueryString("usr")

Response.Write ("usr")
%>
**
this is the ASP code when using the POST method
<%@ LANGUAGE = Python%>

<%
import sys
sys.stdout=sys.stdin
usr = Request.Form ("usr")
Response.Write (str(usr))
%>
**

POST by the way seems to have a 100 kb limit so why ever use it unless
you need to keep the data out of the URL?)
--
http://mail.python.org/mailman/listinfo/python-list


asp oddness , why specify ASP twice

2008-11-26 Thread davidj411
for some reason this code works:
*
<%@ LANGUAGE = Python%>
<%
Response.Write ("test")
%>
*


but this code does NOT:
*
<%@ LANGUAGE = Python
Response.Write ("test")
%>
*

the difference between the two is that i remove "%>" from the first
line and removed "<%" from the next line.
it would seem that this should put all the code into one "ASP block"
but for some reason it does not run.

any ideas? thanks
--
http://mail.python.org/mailman/listinfo/python-list


IIS python web application mapping issue - resolved

2009-04-03 Thread davidj411
i searched the internet for an hour , never found this info, and
figured it out myself.
posting this so that others won't have to look so hard.

ran across this issue and it seems that nobody really documented this
correctly on http://support.microsoft.com/kb/276494

in IIS i could not add the "python mapping" to the web mappings like
this:
"c:\\python.exe -u %s %s"


windows said the file does not exist, even when i unchecked the option
to make sure it exists (and it does exist!).

it would not allow the arguments, i.e. it allowed the mapping when i
just used "c:\\python.exe".

solution was to do it like this:
c:\\python.exe -u "%s %s"

making the arguments have there own set of quotes.


remember to also do the following
have web service extensions enabled for cgi.
register python using pyscript.py.

thanks!

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


Re: IIS python web application mapping issue - resolved

2009-04-03 Thread davidj411
I thought i was being clever but not only did i typo , but it does not
work with the "-u" for unbuffered option.

remove the "-u" to avoid the ugly message:

CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers.

I am going to use the CGI script to upload files (.exe and .zip files)
and had read that "-u" would be needed.

i am going to need to research how this is done now that "-u" is a
known issue with IIS.
i think that i will need to baseencode64 the data before writing it to
a file. not sure really...
any thoughts are appreciated.
--
http://mail.python.org/mailman/listinfo/python-list


cgi file limit size?

2009-04-06 Thread davidj411
I am wondering where the limitation of filesize comes from when i
upload a large file.
it uploads when the filesize is less than 20 MB (but not if larger).
the script does not limit the filesize so it is either an HTTP
specification or a webserver limit, right?
maybe my connection to the server is timing out during the upload?
web server is IIS 6.0.
python is 2.5.2.
IIS webmapping does not use "-u" b/c nothing works when that option is
used.

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


Re: cgi file limit size?

2009-04-09 Thread davidj411
i am using these modules:

import cgi,time
import cgitb; cgitb.enable()

iis webmapping now works with -U (key was to remove '-u' from the
grouping of "s"'s:
C:\Python25\python.exe -u "%s %s"

here is the form html code:
Server name:

File name:



i increased the timeout on the IIS server to 2,200 seconds and i can
now upload a file that is 220 MB in size in about 350 seconds.

if i try to upload a 300 MB file, i get the dreaded CGI bad headers
message,
"CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers."

the headers are always the same:
print "Content-type: text/html\n"
print HTML_TEMPLATE

in the IIS log, i do see http error 400 with sc-win32-status of 64
this link explains 400 errors a little - >http://www.checkupdown.com/
status/E400.html

httperr log shows "BadRequest DefaultAppPool"

this link explains this particular case a little: ->
http://objectmix.com/inetserver/284871-re-sc-status-400-sc-win32-status-64-what-causes.html

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


FTP upload issue

2008-05-15 Thread davidj411
I am having difficulty uploading a text file using Python 2.5 on MAC
OSX.

SCRIPT

filename='/tmp/mac.info2.txt'
fh=open(filename,'w')
fh.write('yes, i have a mac but don't hold that against me - just
example data')
fh.close()


from ftplib import FTP
'host, username, and password are string variables that have already
been defined.
ftp = FTP(host)
ftp.login(username,password)
'so far, logged in, all is well , error is on next line.

ftp.storlines("STOR" + filename, file(filename))
ftp.quit()

What am i doing wrong?  the file DOES exist, the path is correct, and
the file  was closed after being written. file(filename) should open
it again for the upload?

http://www.python.org/doc/lib/ftp-objects.html says that the command
should be an appropriate "STOR" command: "STOR filename". file is an
open file object which is read...


ERROR
  File "mac.inventory.py", line 44, in 
ftp.storlines("STOR " + filename, file(filename))
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/ftplib.py", line 437, in storlines
conn = self.transfercmd(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/ftplib.py", line 356, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/ftplib.py", line 327, in ntransfercmd
resp = self.sendcmd(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/ftplib.py", line 241, in sendcmd
return self.getresp()
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/ftplib.py", line 216, in getresp
raise error_perm, resp
ftplib.error_perm: 550 /tmp/mac.info2.txt: The system cannot find the
path specified.


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


function returns , but variable values has not changed in the interactive prompt

2008-05-23 Thread davidj411
if you run execfile function to run a python script and that script
has variables and functions, should't those variable change in the
interactive prompt too?

script snippet that calls the function which should return like this
return (stuffedname,bigstring, numbertimes,num_times_search_string)

this is the variable that calls the functions. when a function returns
something AND there is a variable set as shown immediately below,
does't the variable get updated?

tu_count = CountStrings (name, balance, searchstr)

this is the output from the script.
notice how tu_count actually differs when called from interactive
prompt after script exits.

tu_count: ('peterjackson', 'peterjacksonpeterjacksonpeter', 2, 0)


>>> tu_count
('davidjacksondavidjacksondavid', 2, 0)

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


csv iterator question

2008-05-23 Thread davidj411
When you save an open file to a variable, you can re-use that variable
for membership checking.
it does not seem to be that way with the csv.reader function, even
when set to a variable name.

what is the best way to store the open CSV file in memory or do i need
to open the file each time?

example of open method on file object:
fhandle=open(filename).readelines()

example of csv.reader method:
reader = csv.reader(open(csvfilename))


here are my results:
>>> reader = csv.reader(open('export.csv'))
>>> for line in reader:
...  print line




but when i try to iterate through it again, it appears to print
nothing (no error either). the file is exhausted?

>>> for line in reader:
...  print line
...

do i need to seek() the beginning of this file object ? any help is
greatly appreciated here.
--
http://mail.python.org/mailman/listinfo/python-list


Re: convert string number to real number - ValueError: invalid literal for int() with base 10: '"2"'

2008-05-28 Thread davidj411
On May 28, 2:22 am, Kam-Hung Soh <[EMAIL PROTECTED]> wrote:
> David Jackson wrote:
> > i used the csv module and saved its contents to a list.
>
> > ['Date', 'No.', 'Description', 'Debit', 'Credit']
> > ['3/17/2006', '5678', 'ELECTRONIC PAYMENT', '', '11.45']
> > ['3/04/2007', '5678', 'THE HOME DEPOT 263 SomeCity FL', '', '25.40']
>
> > the credit/debit fields are strings.
> > what should i have done within the CSV module to make numbers appear as
> > numbers?
> > how can i remove the quotes to make them numbers? i realize i posted a
> > solution to this once before (same posting thread) but i am thinking
> > there is a better method.
>
> There doesn't seem to be a way to describe how specific columns should
> be processed in the csv module.  You could define a conversion function
> that "guesses" the best conversion, for example:
>
> def str2num(datum):
>         try:
>                 return int(datum)
>         except:
>                 try:
>                         return float(datum)
>                 except:
>                         return datum
>
> for row in csv.reader(file(r'Transaction.csv')):
>         [str2num(cell) for cell in row]
>
> ['Date', 'No.', 'Description', 'Debit', 'Credit']
> ['3/17/2006', 5678, 'ELECTRONIC PAYMENT', '', 11.449]
> ['3/04/2007', 5678, 'THE HOME DEPOT 263 SomeCity FL', '',
> 25.399]
>
> --
> Kam-Hung Soh http://kamhungsoh.com/blog";>Software Salariman

I like the str2num function approach, but then i get left with a float
that has more than 2 decimal spaces , i.e. 11.50 becomes
11.449 and round will not fix that.
--
http://mail.python.org/mailman/listinfo/python-list


sublassing as a verb

2008-06-20 Thread davidj411
docs on urllib module say this about the FancyUrlOpener:
"class FancyURLopener( ...)

FancyURLopener subclasses URLopener providing default handling
for ..."

does that mean the FancyURLopener is a subclass of URLopener?
--
http://mail.python.org/mailman/listinfo/python-list


Using Python Scripts with IIS - ASP or Python-based CGI scripts with IIS - which makes more sense?

2008-06-27 Thread davidj411
when does is make sense to use a ASP style Page (.psp) over a Python-
based CGI script with IIS.
?

http://support.microsoft.com/kb/276494

ASP requires registering the python engine.

which has better performance?
The ASP style uses a new part of the python language which is
unfamiliar to me, e.g. "Response.Write('Python Test')" . Where can
i learn about the syntax for ASP (PSP) with Python?

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


sqlite3 .mode option to create HTML table automatically?

2009-12-22 Thread davidj411
the CLI for sqlite3 shows .mode of "html", which formats the output in
HTML format that is good to add to .

BUT i have not yet found anything for sqlite in python that does this.

in fact, i found an old post saying 'if you want the output in a
table, you must create it yourself'.

Does anyone know if this is still the case?

also, i'd like to know if i can get headers in the result set.
The CLI uses '.header ON' to enable this.
is there a place where i can change this too?

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


multivariable assignment

2009-12-31 Thread davidj411
I am not sure why this behavior is this way.
at beginning of script, i want to create a bunch of empty lists and
use each one for its own purpose.
however, updating one list seems to update the others.

>>> a = b = c = []
>>> a.append('1')
>>> a.append('1')
>>> a.append('1')
>>> c
['1', '1', '1']
>>> a
['1', '1', '1']
>>> b
['1', '1', '1']
-- 
http://mail.python.org/mailman/listinfo/python-list


WMI remote call in python script to create process on remote windows computer

2009-10-06 Thread davidj411
import win32com.client
computer = "server"
strUser = "server\user_name"
strPassword ="my_password"
objSWbemLocator = win32com.client.Dispatch
("WbemScripting.SWbemLocator")
objSWbemServices = objSWbemLocator.ConnectServer(computer, "root
\cimv2",strUser,strPassword)
objCreateProc = objSWbemServices.Get("Win32_Process")
ProcessID  = u"200"
objCreateProc.Create(u"cabarc n c:\\temp\\test123.PY.cab c:\\temp\
\dmj.new.log",u"c:\\temp",u' ',ProcessID )

error returned:
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\path\remote.process.py", line 20, in 
objCreateProc.Create(u"cmd /c cabarc n c:\\temp\\test123.PY.cab c:\
\temp\\new.log",u"c:\\temp",u'',ProcessID )

what is causing this "int" error?

i have tried this with and without Unicode.
i'd like to do this without having a need to use Tim Golden's wmi
module.
-- 
http://mail.python.org/mailman/listinfo/python-list


best performance for storage of server information for python CGI web app?

2009-11-18 Thread davidj411
I am wondering what will give me the best performance for storing
information about the servers in our environment.
currently i store all info about all servers in a single shelve file,
but i have concerns.
1) as the size of the shelve file increases, will performance suffer ?
2) what about if 2 updates occur at the same time to the shelve file?
when a shelve file is opened, is the whole file read into memory?

if either scenario (1 or 2) is true, then should i think about
creating a shelve file per server?
i was also thinking about using SQL Lite with one DB to store all the
info.
with this option, i would not have to worry about concurrent updates,
but as the file size increases, i could expect performance to suffer
again?

I am running Python 2.6 CGI scripts on Apache web server on windows
platform. they interact with the current shelve file to pull info or
request info from a python service which will go collect the info and
put it into the shelve file.
-- 
http://mail.python.org/mailman/listinfo/python-list


time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order

2009-07-21 Thread davidj411
I am using a recursive function to print the time and a few other
things on each pass. ( the function calculates size of file that is
being transferred and if not 100 % copied, it waits 20 secs and checks
again).

i would expect the time to be correct anytime it is used:

<--code below -->>
print time.strftime('%m-%d-%Y %H:%m:%S')
<--code above -->>

here is an example of what i am seeing:

16:07:16
16:07:36
16:07:56
16:07:16
16:07:36
16:07:56
16:07:16
16:07:36
16:07:56
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order

2009-07-21 Thread davidj411
On Jul 21, 5:29 pm, Simon Forman  wrote:
> On Jul 21, 5:00 pm, davidj411  wrote:
>
>
>
>
>
> > I am using a recursive function to print the time and a few other
> > things on each pass. ( the function calculates size of file that is
> > being transferred and if not 100 % copied, it waits 20 secs and checks
> > again).
>
> > i would expect the time to be correct anytime it is used:
>
> > <--code below -->>
> > print time.strftime('%m-%d-%Y %H:%m:%S')
> > <--code above -->>
>
> > here is an example of what i am seeing:
>
> > 16:07:16
> > 16:07:36
> > 16:07:56
> > 16:07:16
> > 16:07:36
> > 16:07:56
> > 16:07:16
> > 16:07:36
> > 16:07:56
>
> Your output doesn't match your format string:
>
> In [1]: import time
>
> In [2]: print time.strftime('%m-%d-%Y %H:%m:%S')
> 07-21-2009 17:07:16
>
> There's no way to tell why your output times seem to repeat without
> seeing the code that surrounds your "print time.strftime('%m-%d-%Y %H:
> %m:%S')" line.

sorry, yes, i did manually filter the output.

here is the function:

def log_out(msg,servername='std.out'):
print msg
open(log_dir + '\\' + servername + ".log",'a').write(servername + "-"
+ time.strftime('%m-%d-%Y %H:%M:%S') + " " + msg+'\n')

on each pass, it should output the newer time (whether recursive or
not, right) ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order

2009-07-22 Thread davidj411
i never heard of the logging module, but this function seemed simple
enough.

i assume this link is what you refering to:
http://docs.python.org/library/logging.html

thanks for the helpful info. i think "Piet van Oostrum" has resolved
my issue. good eyes!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can a child thread notify a parent thread its status?

2009-07-27 Thread davidj411
could i see an example of this maybe?
-- 
http://mail.python.org/mailman/listinfo/python-list