permission issue with zipfile

2017-09-04 Thread loial
I am getting a permission issue with the following code 


targetDirectory = '/data/upload' 

self.ZIPFileName = targetDirectory + os.sep + "MY.ZIP" 

zf = zipfile.ZipFile(self.ZIPFileName, mode='w') 


 [Errno 13] Permission denied: '/data/upload/MY.ZIP' 



The target directory is an NFS mounted directory. 

I can manually create a file in that directory with no issues using the same 
user 

Any ideas? 

Python version is 2.7.10. Platform is Centos 7 
-- 
https://mail.python.org/mailman/listinfo/python-list


Permissions issues with zipfile

2017-09-04 Thread loial
I am getting a permission issue with the following code


targetdirectory = '/data/upload'

self.ZIPFileName = targetDirectory + os.sep + "MY.ZIP" 

zf = zipfile.ZipFile(self.ZIPFileName, mode='w') 


 [Errno 13] Permission denied: '/data/upload/MY.ZIP' 



The target directory is an NFS mounted directory.

I can manually create a file in that directory with no issues using the same 
user

Any ideas?

Python version is 2.7.10. Platform is Centos 7


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


Issue with zipfile and symbolic link

2017-05-30 Thread loial
I am reading a list of pdf files from a directory which is a symbolic link and 
adding them to a zip file.

Issue I have is that the zip files are being added as empty directories rather 
than the actual pdf files.

My code is below. Any idea why this happening?

   # ZIP pdfs subdirectory if it exists

sourcefile = self._dir + os.sep + "pdfs"
targetname = "pdfs"

if os.path.exists(sourcefile):
   zf.write(sourcefile,targetname, compress_type=compression)

   for file in os.listdir(sourcefile):
   targetname = "pdfs" + os.sep + file
   zf.write(sourcefile,targetname, compress_type=compression)

# Close zip file

zf.close()
-- 
https://mail.python.org/mailman/listinfo/python-list


newbie question re classes and self

2017-03-28 Thread loial
Can I pass self(or all its variables) to a class?

Basically, how do I make all the variables defined in self in the calling 
python script available to the python class I want to call?



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


Extract sigle file from zip file based on file extension

2017-02-10 Thread loial
I need to be able to extract a single file from a .zip file in python.
The zip file will contain many files. The file to extract will be the only .csv 
file in the zip, but the full name of the csv file will not be known.

Can this be done in python?
-- 
https://mail.python.org/mailman/listinfo/python-list


ZipImportError: can't find module

2016-05-24 Thread loial
I am suddenly having a problem with importing a module from a zip file in 
Python 2.4.1

What has been working for years suddenly has an error :

zipimport.ZipImportError: can't find module 'mymodule'

PYTHONPATH is correct, it points to the zip file containing mymodule

N.B. the python script(unchanged) is called from a shell script using

python myscript.py

The python script also has a shebang line that references the 2.4.1 install of 
Python.

Debugging the script shows that PYTHONPATH is set correctly, it points to the 
zip file containing mymodule

Any ideas?

Platform is Solaris 10
-- 
https://mail.python.org/mailman/listinfo/python-list


smtplib not working when python run under windows service via Local System account

2016-05-05 Thread loial
I have a python 2.7.10 script which is being run under a windows service on 
windows 2012 server .
The python script uses smtplib to send an email.

It works fine when the windows service is run as a local user, but not when the 
windows service is configured to run as Local System account. I get no 
exception from smtplib, but the email fails to arrive.

Any ideas?

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


Re: Can't run lpr from python on windows 2012 server

2016-04-22 Thread loial
Yes it does. I finally found the solution here :

http://www.tomshardware.co.uk/forum/240019-44-error-windows

Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the 
sysWOW64 folder




On Friday, April 22, 2016 at 3:27:18 PM UTC+1, Random832 wrote:
> On Fri, Apr 22, 2016, at 10:15, loial wrote:
> > I am reposting this question in a simpler form.
> > 
> > I can run lpr from the command prompt but not from python
> > 
> > os.system("notepad") works
> > os.system("lpr") does not work. Basically it says lpr is not a known
> > program or executable
> > 
> > Why can I run lpr from the windows command prompt but not from
> > python(2.7)
> 
> Does lpr.exe actually physically exist in c:\windows\system32 as you
> have indicated in the your earlier posts? I.e. if you actually browse
> system32 with the file manager will you see lpr.exe? The problem with
> your question is that it's not a standard command, so none of the rest
> of us have it, which means we're half-blind trying to find your problem.

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


Re: Running lpr on windows from python

2016-04-22 Thread loial
I finally found the solution here :

http://www.tomshardware.co.uk/forum/240019-44-error-windows

Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the 
sysWOW64 folder

Thanks for all your efforts
-- 
https://mail.python.org/mailman/listinfo/python-list


Can't run lpr from python on windows 2012 server

2016-04-22 Thread loial
I am reposting this question in a simpler form.

I can run lpr from the command prompt but not from python

os.system("notepad") works
os.system("lpr") does not work. Basically it says lpr is not a known program or 
executable

Why can I run lpr from the windows command prompt but not from python(2.7)

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


Re: Running lpr on windows from python

2016-04-22 Thread loial
Nothing seems to work.

Even doing

import os
os.system("lpr")

still returns 
'lpr' is not recognized as an internal or external command,operable program or 
batch file.


Even though I can run lpr fine from the command prompt

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


Re: Running lpr on windows from python

2016-04-20 Thread loial
I get the same issue if I just specify "lpr" rather than a full path, i.e. it 
works from the command prompt(with forward slashes), but not from python 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Running lpr on windows from python

2016-04-20 Thread loial
As I said, the lpr command works fine from the command prompt but not from 
python.

Everything is 64-bit (windows server 2012).

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


Running lpr on windows from python

2016-04-20 Thread loial
I am trying to run lpr from python 2.7.10 on windows

However I always get the error
'C:/windows/system32/lpr.exe ' is not recognized as an internal or external 
command,
operable program or batch file.

Even though typing the same at the  command prompt works OK


Any ideas?

I am using subprocess as follows

process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)

where command line is
C:/windows/system32/lpr.exe -S 172.28.84.38 -P RAW C:/john/myfile
-- 
https://mail.python.org/mailman/listinfo/python-list


can't decompress data; zlib not available

2016-01-11 Thread loial
I am migrating a python script from Red hat linux REL 6.6 to AIX 7.1

I am using python 2.7.10

On AIX I the ror

zipimport.ZipImportError: can't decompress data; zlib not available

Any ideas how to get this to work on AIX?



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


Modify environment variable for subprocess

2015-09-23 Thread loial
I need to modify the LIBPATH environment variable when running a process via 
subprocess, but otherwise retain the existing environment.

Whats the best way to do that?

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


Re: passing double quotes in subprocess

2015-09-08 Thread loial
Yep, that did the trick...cheers

On Tuesday, September 8, 2015 at 12:04:05 PM UTC+1, loial wrote:
> I need to execute an external shell script via subprocess on Linux.
> 
> One of the parameters needs to be passed inside double quotes 
> 
> But the double quotes do not appear to be passed to the script
> 
> I am using :
> 
> myscript = '/home/john/myscript'
> commandline = myscript + ' ' + '\"Hello\"'
> 
> process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, 
> stderr=subprocess.PIPE)
> output,err = process.communicate()
> 
> 
> if I make the call from another shell script and escape the double quotes it 
> works fine, but not when I use python and subprocess.
> 
> I have googled this but cannot find a solution...is there one?

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


passing double quotes in subprocess

2015-09-08 Thread loial
I need to execute an external shell script via subprocess on Linux.

One of the parameters needs to be passed inside double quotes 

But the double quotes do not appear to be passed to the script

I am using :

myscript = '/home/john/myscript'
commandline = myscript + ' ' + '\"Hello\"'

process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
output,err = process.communicate()


if I make the call from another shell script and escape the double quotes it 
works fine, but not when I use python and subprocess.

I have googled this but cannot find a solution...is there one?
-- 
https://mail.python.org/mailman/listinfo/python-list


U.K. Royal Mail MailMark web service from python?

2015-04-13 Thread loial
Anyone out there got any examples of calling the UK Royal Mail Mailmark web 
service from python?


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


Re: Concatenate list values

2015-02-24 Thread loial
Many thanks for those you chose to help me out. Problem solved.
-- 
https://mail.python.org/mailman/listinfo/python-list


Concatenate list values

2015-02-23 Thread loial
Is there a quick way to concatenate all the values in a list into a string, 
except the first value?

I want this to work with variable length lists.

All values in list will be strings.

Any help appreciated
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python path on windows

2015-02-20 Thread loial
On Friday, February 20, 2015 at 2:54:26 PM UTC, Ian wrote:
> On Feb 20, 2015 7:46 AM, "loial"  wrote:
> 
> >
> 
> > On Linux we use
> 
> > #!/usr/bin/env python
> 
> >
> 
> > At the start of scripts to ensure that the python executable used is the 
> > one defined in the PATH variable, rather than hardcoding a path to the 
> > python executable.
> 
> >
> 
> > What is the equivalent functionality in Windows?
> 
> https://docs.python.org/3/using/windows.html#launcher
> 
> Note that while the launcher can be used with any version of Python, it is 
> only packaged with 3.3+.

Vesrion is 2.6
-- 
https://mail.python.org/mailman/listinfo/python-list


Python path on windows

2015-02-20 Thread loial
On Linux we use 
#!/usr/bin/env python

At the start of scripts to ensure that the python executable used is the one 
defined in the PATH variable, rather than hardcoding a path to the python 
executable.

What is the equivalent functionality in Windows?

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


Web services from python

2014-10-27 Thread loial
What is the best package to use with python 2.6 to access Web services. Is it 
ZSI?

Can anyone recommend a good tutorial, preferably with a sandbox web service?

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


reading file in for loop

2014-09-05 Thread loial
If I read a file using a for loop, as follows, is the file left open if I 
execute a break in the for loop?


for line in open(myFile).readlines():

if something:
break


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


capturing SNMP trap events

2014-07-04 Thread loial
I want to monitor printers for events such as the completion of printing. 
If the printer initiates an SNMP trap event when the job has finished printing, 
how can I capture this?

Presumably I need some sort of deamon to listen for these trap messages. I have 
looked at pySNMP but am not sure if this can be used to capture SNMP trap 
events from the printer.

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


Re: find and replace string in binary file

2014-03-05 Thread loial
Thanks Emile.

Unfortunately I have to use python 2.6 for this


On Wednesday, 5 March 2014 00:13:00 UTC, emile  wrote:
> On 03/04/2014 02:44 PM, Chris Angelico wrote:
> 
> > On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <__pete...@web.de> wrote:
> 
> >> loial wrote:
> 
> >>
> 
> >>> How do I read a binary file, find/identify a character string and replace
> 
> >>> it with another character string and write out to another file?
> 
> >>>
> 
> >>> Its the finding of the string in a binary file that I am not clear on.
> 
> >>
> 
> >> That's not possible. You have to convert either binary to string or string
> 
> >> to binary before you can replace. Whatever you choose, you have to know the
> 
> >> encoding of the file.
> 
> >
> 
> > If it's actually a binary file (as in, an executable, or an image, or
> 
> > something), then the *file* won't have an encoding, so you'll need to
> 
> > know the encoding of the particular string you want and encode your
> 
> > string to bytes.
> 
> 
> 
> 
> 
> On 2.7 it's as easy as it sounds without having to think much about 
> 
> encodings and such.  I find it mostly just works.
> 
> 
> 
> emile@paj39:~$ which python
> 
> /usr/bin/python
> 
> emile@paj39:~$ python
> 
> Python 2.7.3 (default, Sep 26 2013, 16:38:10)
> 
> [GCC 4.7.2] on linux2
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
>  >>> image = open('/usr/bin/python','rb').read()
> 
>  >>> image.find("""Type "help", "copyright", "credits" """)
> 
> 1491592
> 
>  >>> image = image[:1491592]+"Echo"+image[1491592+4:]
> 
>  >>> open('/home/emile/pyecho','wb').write(image)
> 
>  >>>
> 
> emile@paj39:~$ chmod a+x /home/emile/pyecho
> 
> emile@paj39:~$ /home/emile/pyecho
> 
> Python 2.7.3 (default, Sep 26 2013, 16:38:10)
> 
> [GCC 4.7.2] on linux2
> 
> Echo "help", "copyright", "credits" or "license" for more information.
> 
> 
> 
> YMMV,
> 
> 
> 
> Emile

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


find and replace string in binary file

2014-03-04 Thread loial
How do I read a binary file, find/identify a character string and replace it 
with another character string and write out to another file?

Its the finding of the string in a binary file that I am not clear on.

Any help appreciated
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Add directory to sys.path based on variable

2014-01-30 Thread loial
Idiot that I am...I was not calling the script with the full path !

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


Re: Add directory to sys.path based on variable

2014-01-30 Thread loial
Ok, that works fine with the apth hard coded, but I want to do something like 
the code below. i.e I am trying to dynamically add a path that is relative to 
the path of the current executing python script.

In this case the import fails.

import sys
import os
from os.path import *

scriptpath=os.path.dirname(sys.argv[0])
otherscriptspath=printerpath.replace("scripts","otherscripts")
sys.path.append(otherscriptspath)

from AuditUpdate import *



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


Add directory to sys.path based on variable

2014-01-30 Thread loial
I want to add a path to sys.path based upon a variable

Can I do that?

Hardcodeing the path works fine, but I want to set it based upon a variable.

I know I can set PYTHONPATH, but just wondering if I can add a directory on the 
fly to sys.path using a variable





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


Using netrc when user password is blank

2013-09-05 Thread loial
I am having issues using the netrc package for users where the password is 
blank.
It works fine for users with password is not blank and is spacified in the 
.netrc 

I am not sure if this is an issue with the .netrc file or my use of the .netrc 
package.

.netrc file looks like :

machine myserver login john password 


Code is


username, ignore, password = netrc.netrc().hosts[hostname]


This fails saying the .netrc is malformed.
 
How should I specify the line in  the .netc when the password is blank? Or is 
it not possible



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


Re: How to clean up socket connection to printer

2013-07-15 Thread loial
Well, I certainly suspect the customers network connection to the printer which 
is over a WAN across half of Europe, but proving that is the problem is another 
matter.

I can replicate a "Connection reset by peer" error on own printer by pulling 
the network cable out of the printer. And again I thereafter get the issue of 
"Connection refused" for what seems a variable amount of time.

But at least I am now reassured that the "Connection Refused" is not due to 
something my script has not cleaned up.

Thanks

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


Re: How to clean up socket connection to printer

2013-07-11 Thread loial
Replies to questions :

1. Does the printer accept connections again after some time? 

Yes, bit seems to vary how long that takes

2. Does the printer accept connections if you close and re-open the 
Python interpreter?

Not after a Connection reset error. The script exits after trapping the 
"Connection reset by peer" error and it is only when a new instance of the 
script is kicked off that the "Connection refused" issue is encountered.
 
3. Is there actually a limit to the number of concurrent connections? In 
other words, what happens when you try to create a second connection 
without closing the first? 

I get the Connction refused error in that scenerio too, but as my script exits 
after detecting the "Connection reset by peer error" there is only ever one 
instance of my script running(and therefore one attempt to connect) at a time, 
Which is why I am wondering whether the connection is closed properly by my 
code when the script exits afer the "Connection reset by peer" error. Or is it 
the printer not cleaning up the connection.?



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


How to clean up socket connection to printer

2013-07-09 Thread loial
I have a socket application that is connecting to a HP printer via port 9100.

Occassionally I get a "Connection reset by peer" error which I am trapping and 
exiting the script with an error message.

That works Ok, the issue I have is that the next time I run the script I get
"Connection refused" from the printer, which suggests that the printer still 
thinks the port is is busy, though nothing is printing. I suspect that in some 
way my socket connection has not been closed correctly?

When I get the "Connection rest by peer" error, I attempt to close the port as 
follows :

try:
sock.close()
del sock
except Exception, e:
pass

Is there anything else I should do in these circumstances to ensure that my 
socket connection is closed OK? 

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


Diagnosing socket "Connection reset by peer"

2013-05-22 Thread loial
I have a sockets client that is connecting to a printer and occassionally 
getting the error "104 Connection reset by peer"

I have not been able to diagnose what is causing this. Is there any additional 
traceing I can do(either within my python code or on the network) to establish 
what is causing this error?

Currently I am simply trapping socket.erruor 

Python version is 2.6






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


How to raise a socket "104 connection reset by peer error"

2013-05-21 Thread loial
For testing purposes I want my code to raise a socket "connection reset by 
peer" error, so that I can test how I handle it, but I am not sure how to raise 
the error.

Any advice appreciated

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


spilt question

2013-05-16 Thread loial
I want to split a string so that I always return everything BEFORE the LAST 
underscore

HELLO_.lst # should return HELLO
HELLO_GOODBYE_.ls  # should return HELLO_GOODBYE

I have tried with rsplit but cannot get it to work.

Any help appreciated

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


subprocess question re waiting

2013-04-08 Thread loial
I want to call a child process to run a shell script and wait for that script 
to finish. Will the code below wait for the script to finish? If not then how 
do I make it wait?

Any help appreciated.


import subprocess

command = "/home/john/myscript"

process = subprocess.Popen(command, 
stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
close_fds=True, shell=True)

out, err = process.communicate()
returncode = process.returncode
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading file issue

2013-01-28 Thread loial
Thanks for confirming my sanity



On Monday, 28 January 2013 11:57:43 UTC, Chris Angelico wrote:
> On Mon, Jan 28, 2013 at 10:47 PM, loial  wrote: > I am 
> parseing a file to extract data, but am seeing the file being updated even 
> though I never explicitly write to the file. It is possible that another 
> process is doing this at some later time, but I just want to check that 
> opening the file as follows and ignoring a record would not result in that 
> record being removed from the file. > > I'm damned sure it wouldn't, but just 
> wanted to check with the experts!. > > for line in open("/home/john/myfile"): 
> Absolutely not. You're opening the file (by default) for reading only. That's 
> not going to edit the file in any way. (It might cause the directory entry to 
> be rewritten, eg last-access time, but not the file contents.) Your 
> expectation is 100% correct. ChrisA

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


Reading file issue

2013-01-28 Thread loial
I am parseing a file to extract data, but am seeing the file being updated even 
though I never explicitly write to the file. It is possible that another 
process is doing this at some later time, but I just want to check that opening 
the file as follows and ignoring a record would not result in that record being 
removed from the file.

I'm damned sure it wouldn't, but just wanted to check with the experts!.


for line in open("/home/john/myfile"):
linecount = linecount + 1

if linecount == 1:  # ignore header
continue


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


Find lowest level directory

2012-12-13 Thread loial
How can I find the full path of the lowest level directory in a directory 
structure?
 
If there is more than one directory at the lowest level, the first one found 
will be enough.

Any help appreciated
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string contains and special characters

2012-10-09 Thread loial
On Tuesday, 9 October 2012 15:19:33 UTC+1, Agon Hajdari wrote:
> On 10/09/2012 04:02 PM, loial wrote: > I am trying to match a string that 
> containing the "<" and ">" characters, using the string contains function, 
> but it never seems to find the lines containing the string > > e.g if 
> mystring.contains("") : > > Do I need to escape the characters...and if 
> so how? > if '' in yourstring: # your code -- Agon Hajdari

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


string contains and special characters

2012-10-09 Thread loial
I am trying to match a string that containing the "<" and ">" characters, using 
the string contains function, but it never seems to find the lines containing 
the string

e.g if mystring.contains("") :

Do I need to escape the characters...and if so how?

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


sockets,threads and interupts

2012-09-04 Thread loial
I have threaded python script that uses sockets to monitor network ports.

I want to ensure that the socket is closed cleanly in all circumstances. This 
includes if the script is killed or interupted in some other way.

As I understand it signal only works in the main thread, so how can I trap 
interupts in my threaded class and always ensure I close the socket? Using 
KeyboardInterupt does not seem to work.


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


Threads and sockets

2012-08-10 Thread loial
I am writing an application to send data to a printer port(9100) and then 
recieve PJL responses back on that port. Because of the way PJL works I have to 
do both in the same process(script).

At the moment I do not start to read responses until the data has been sent to 
the printer. However it seems I am missing some responses from the printer 
whilst sending the data, so I need to be able to do the 2 things at the same 
time.

Can I open a port once and then use 2 different threads, one to write to the 
post and one to read the responses)?
 

 

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


pycups

2012-08-09 Thread loial
I am looking to monitor print jobs on linux via python.

pycups looks a possibility, but I cannot find any useful tutorial, examples of 
how to use it.

Can anyone help?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie socket help

2012-02-06 Thread loial
OS is Red hat enterprise linux 5.5 and python version is 2.6



On Feb 2, 4:34 pm, Dennis Lee Bieber  wrote:
> On Thu, 2 Feb 2012 05:53:22 -0800 (PST), loial 
> wrote:
>
> >I am trying to write a python script to read data from a printer port
> >using python sockets, but it seems I am locking up the port.
>
> >Is there a way to ensure that I do not block the port to other
> >applications?
>
> >My knowledge of python sockets is minimal, so any help would be
> >appreciated.
>
>         OS and Python version might be of interest...
>
>         However, parallel ports are typically unshared devices (which is why
> any multitasking system has things like print spooling -- so multiple
> tasks and "print" to the spool, and the spool driver is the only process
> actually accessing the printer port).
>
>         I still have nightmares over one assignment I had some 8 years ago:
> Reading a clock signal (square wave) on one of the parallel port's
> signal pins, in order to time a three-bit /balanced/ (using 6-pins of
> the output) data stream. Done on a W98 laptop (since W98 didn't have the
> protected ports of WinXP) using Visual C++  -- and on the laptop as the
> eventual plan had been to send "red" GPS decryption keys to satellites;
> contact with "red" keys makes the hardware it passes through highly
> classified, and the main hardware had to stay "open" for uncleared
> developers working on flight software.
>
>         Unfortunately, even with the program running at the highest
> available Windows priority, the OS still did  every few
> milliseconds, which led to glitches in the output stream. (The good
> news: by the time the DTD with the keys became available, the CONOPS had
> changed to use "black" keys, which did not "infect" the computer system
> -- so the regular command formatter could be used for uploading).
>
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfr...@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


newbie socket help

2012-02-02 Thread loial
I am trying to write a python script to read data from a printer port
using python sockets, but it seems I am locking up the port.

Is there a way to ensure that I do not block the port to other
applications?

My knowledge of python sockets is minimal, so any help would be
appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Hardlink sub-directories and files

2011-08-02 Thread loial
I am trying to hardlink all files in a directory structure using
os.link.

This works fine for files, but the directory also contains sub-
directories (which themselves contain files and sub-directories).
However I do not think it is possible to hard link directories ?

So presumably I would need to do a mkdir for each sub-directory
encountered?
Or is there an easier way to hardlink everything in a directory
structure?.

The requirement is for hard links, not symbolic links

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


Re: Passing array from java to python

2011-06-02 Thread loial
Unfortunately using jpython or json are not options at the moment
-- 
http://mail.python.org/mailman/listinfo/python-list


Passing array from java to python

2011-06-02 Thread loial
I need to pass some sort of array or hashmap from Java and read the
data in a python script (which will be called by the java class). Is
there any neater way  to do this other than just passing strings?

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


Re: Python 2.6 and timezones

2011-05-23 Thread loial
Thanks...but being a python newbie I am struggling to understand how
to do this.

How can I use tzinfo to do the equivalent of what I do in Java, which
is  :

TimeZone tz1 = TimeZone.getDefault();

long localOffset = tz1.getOffset(date.getTime());

TimeZone tz2 = TimeZone.getTimeZone("EST");

long remoteOffset = tz2.getOffset(date.getTime());

Any help appreciated



On May 23, 11:48 am, Daniel Kluev  wrote:
> On Mon, May 23, 2011 at 9:32 PM, loial  wrote:
> > Does python have an equivalent of the java Timezone object?
>
> > I need to be able to get offsets for timezones (only U.S. time zones
> > at the moment)
>
> Depends on what exactly do you want. If you need to convert timezone
> name into current offset, you should use [1] or [2].
> If you just need to handle known offsets for datetime objects, there
> is tzinfo class in datetime module, [3].
>
> [1]http://pypi.python.org/pypi/PosixTimeZone/0.9.4
> [2]http://pypi.python.org/pypi/pytz/2011g
> [3]http://docs.python.org/library/datetime.html#tzinfo-objects
>
> --
> With best regards,
> Daniel Kluev

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


Python 2.6 and timezones

2011-05-23 Thread loial
Does python have an equivalent of the java Timezone object?

I need to be able to get offsets for timezones (only U.S. time zones
at the moment)



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


Spurious character in IOError exception

2011-04-28 Thread loial
When I correctly trap an IOError a spurious u' appears in the file
path in the exception message :

The path used in the code is correct i.e. /home/myfile

But the error message says :

[Errno 2] No such file or directory: u'/home/myfile'


I am simply doing

 except IOError, e:
print str(e)


Any ideas where the 'u  is coming from?

This is python 2.4.1



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


Re: PJL

2011-01-11 Thread loial
Thank you. I was able to send the following PJL to the printer and it
worked.

@PJL STMSG DISPLAY = "Hello from John"

Do you have any experience handling PJL responses from the
printer?...What I really want to do is get PJL information back from
the printer and read it in python(or some other Unix scripting tool)

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


Re: PJL

2011-01-10 Thread loial
Thanks for responding..

First question...how do I send it to the printer?   Printer would be
on the network.
-- 
http://mail.python.org/mailman/listinfo/python-list


PJL

2011-01-10 Thread loial
Anyone got any experience of send PJL commands to a printer using
Python on Unix?

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


Oracle jdbc sql select for update in python

2010-11-17 Thread loial
I want to do a select from...for update in python, update the selected
row and then commit;

However cannot seem to get it to work...the update statement seems to
be waiting because the row is locked. Presumably oracle thinks the
update is another transaction.

How can I get this to work? What statements do I need to ensure Oracle
treats this as one transaction?




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


Scheduling in python

2010-09-23 Thread loial
I want to enable my end users to be able to schedule a task(actually
running another python or shell script). Rather than scheduling it
directly in cron, are there any python modules I could use?

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


Re: How to read large amounts of output via popen

2010-08-06 Thread loial
Ok, thats great. Thanks for the very elegant solution(s)




On 6 Aug, 13:44, Nobody  wrote:
> On Fri, 06 Aug 2010 02:06:29 -0700, loial wrote:
> > I need to read a large amount of data that is being returned in
> > standard output by a shell script I am calling.
>
> > (I think the script should really be writing to a file but I have no
> > control over that)
>
> If the script is writing to stdout, you get to decide whether its stdout
> is a pipe, file, tty, etc.
>
> > Currently I have the following code. It seeems to work, however I
> > suspect this may not work with large amounts of standard output.
> > process=subprocess.Popen(['myscript', 'param1'],
> > shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
>
> > cmdoutput=process.communicate()
>
> It's certainly not the best way to read large amounts of output.
> Unfortunately, better solutions get complicated when you need to read more
> than one of stdout and stderr, or if you also need to write to stdin.
>
> If you only need stdout, you can just read from process.stdout in a loop.
> You can leave stderr going to wherever the script's stderr goes (e.g. the
> terminal), or redirect it to a file.
>
> If you really do need both stdout and stderr, then you either need to
> enable non-blocking I/O, or use a separate thread for each stream, or
> redirect at least one of them to a file.
>
> FWIW, Popen.communicate() uses non-blocking I/O on Unix and separate
> threads on Windows (the standard library doesn't include a mechanism to
> enable non-blocking I/O on Windows).
>
> > What is the best way to read a large amount of data from standard
> > output and write to a file?
>
> For this case, the best way is to just redirect stdout to a file, rather
> than passing it through the script, i.e.:
>
>         outfile = open('outputfile', 'w')
>         process = subprocess.call(..., stdout = outfile)
>         outfile.close()

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


How to read large amounts of output via popen

2010-08-06 Thread loial
I need to read a large amount of data that is being returned in
standard output by a shell script I am calling.

(I think the script should really be writing to a file but I have no
control over that)

Currently I have the following code. It seeems to work, however I
suspect this may not work with large amounts of standard output.

What is the best way to read a large amount of data from standard
output and write to a file?

Here is my code.

process=subprocess.Popen(['myscript', 'param1'],
shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

cmdoutput=process.communicate()

myfile = open('/home/john/myoutputfile','w')

myfile.write(cmdoutput[0])

myfile.close()

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


Re: lpr via subprocess in 2.4

2010-08-04 Thread loial
Thanks...that worked.

I have also been trying to get the return code and standard error.

How do I access these?

#!/usr/bin/python
import os
import subprocess
process=subprocess.Popen(['lpr', '-P' ,'raserlpr','/etc/hosts'],
shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

print process.communicate()








On 4 Aug, 12:08, Peter Otten <__pete...@web.de> wrote:
> loial wrote:
> > I am am trying to run the following command via subprocess
>
> > lpr -P printqueue filetoprint
>
> > I cannot seem to get it to work and return stderr
>
> > I think the issue is how to specify the arguments
>
> > I am trying
>
> > subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
>
> This looks for an executable called "lpr -P"; try
>
> subprocess.Popen(['lpr', '-P' ,'laserlpr','/etc/hosts'], shell=False)
>
>
>
> > but get error :
>
> > Traceback (most recent call last):
> >   File "testopen.py", line 6, in ?
> >     subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
> >   File "/usr/python2.4/lib/python2.4/subprocess.py", line 558, in __in
> > it__
> >     errread, errwrite)
> >   File "/usr/python2.4/lib/python2.4/subprocess.py", line 991, in _exe
> > cute_child
> >     raise child_exception
> > OSError: [Errno 2] No such file or directory- Hide quoted text -
>
> - Show quoted text -

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


lpr via subprocess in 2.4

2010-08-04 Thread loial
I am am trying to run the following command via subprocess

lpr -P printqueue filetoprint

I cannot seem to get it to work and return stderr

I think the issue is how to specify the arguments

I am trying

subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)

but get error :

Traceback (most recent call last):
  File "testopen.py", line 6, in ?
subprocess.Popen(['lpr -P' ,'laserlpr','/etc/hosts'], shell=False)
  File "/usr/python2.4/lib/python2.4/subprocess.py", line 558, in __in
it__
errread, errwrite)
  File "/usr/python2.4/lib/python2.4/subprocess.py", line 991, in _exe
cute_child
raise child_exception
OSError: [Errno 2] No such file or directory

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


Re: Get name of file from directory into variable

2010-08-03 Thread loial
On 3 Aug, 11:31, Alex Willmer  wrote:
> On Aug 3, 11:21 am, loial  wrote:
>
> > In a unix shell script I can do something like this to look in a
> > directory and get the name of a file or files into a variable :
>
> > MYFILE=`ls /home/mydir/JOHN*.xml`
>
> > Can I do this in one line in python?
>
> Depends if you count imports.
>
> import glob
> my_files = glob.glob('/home/mydir/JOHN*.xml')
>
> Regards, Alex

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


Get name of file from directory into variable

2010-08-03 Thread loial
In a unix shell script I can do something like this to look in a
directory and get the name of a file or files into a variable :

MYFILE=`ls /home/mydir/JOHN*.xml`


Can I do this in one line in python?

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


Kick off a delete command from python and not wait

2010-07-20 Thread loial
I have a requirement to kick off a shell script from a python script
without waiting for it to complete. I am not bothered about any return
code from the script.

What is the easiest way to do this. I have looked at popen but cannot
see how to do it.



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


How to print via python on windows

2010-06-14 Thread loial
What is the easiest way to send a text file to a networked printer
from a python script running on windows?

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


Parse xml file

2009-08-27 Thread loial
Is there a quick way to retrieve data from an xml file in python 2.4,
rather than read the whole file?



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


Using optparse

2009-04-23 Thread loial
A shell script is passing parameters to my python script in the
following format

-PARAM1 12345 -PARAM2 67890

Can I parse these with optparse  ? If so how?

I can't seem to get it to work. It seems to expect --PARAM1 and --
PARAM2



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


Get file name from file handle

2009-02-17 Thread loial
Is there anyway, having been passed a file handle, to get the
filename?

I am assuming not, but thought I would ask

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


replace ftp by local copy

2009-02-16 Thread loial
I have been given an old python application that calls ftplib in many
places to copy files to a remote server.

I have been given the task of cloneing this code so that ftp is not
used, but files are just copied locally in a scenerio where ftp is not
available. The code is not well structured which makes this more
difficult.

Before starting this just wondered if anyone has previously done
anything like overriding the ftplib module so that I can leave the
existing code largely unchanged but have the ftp commands just copy
files locally?

Just thought I'd ask before getting started.




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


Re: Using paramiko rsa key

2009-02-10 Thread loial
On 10 Feb, 17:08, "Martin P. Hellwig" 
wrote:
> loial wrote:
> > Can anyone be a little more helpful than Tino?
>
> 
> I'll do some freebie hints :-)
> What I would do is try first whether key authentication works at all,
> for example following a tutorial 
> likehttp://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter8.html
>
> And if that works translate it to the relevant python code.
>
> --
> mph

Thanks..I'll try that first
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using paramiko rsa key

2009-02-10 Thread loial
Can anyone be a little more helpful than Tino?

I have generated the key file as follows on windows and ftp'd the
id_rsa.pub file to the .ssh directory on the server and renamed to
authorized_keys


import paramiko


key = paramiko.RSAKey.generate(2048)

key.write_private_key_file('Z:/id_rsa')
file = open('Z:/id_rsa.pub','w')
file.write("ssh-rsa " +key.get_base64())
file.close()

But when I try to connect as follows I get an authentication failed
error.


import paramiko

paramiko.util.log_to_file('demo_sftp.log')

try:
try:
key = paramiko.RSAKey.from_private_key_file("Z:/id_rsa") #the
generated private key
except Exception, e:
print str(e)
t = paramiko.Transport(('10.5.1.15', 22))
print "here"
t.start_client()
t.auth_publickey('prod2',key)

if t.is_authenticated():
print "Got it!"
sftp = paramiko.SFTPClient.from_transport(t)
dirlist = sftp.listdir('.')
print "Dirlist:", dirlist
t.close()
except Exception, e:
print str(e)
t.close()



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


Using paramiko rsa key

2009-02-10 Thread loial
I want to connect via ssh from a python script on windows to an AIX
server running openSSH using rsa keys rather than a password.

Can anyone provide me with /point me at  a simple tutuorial on the
steps I need to go though in terms of geneerating the key, installing
on the server and connecting in my python code?

Thanks in advance.



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


python ssh and Tetia SSH server

2009-02-10 Thread loial
Anyone out there any experience of using python ssh modules to connect
to the Tetia SSH server from SSH (ssh.com)?



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


Python ssh with SSH Tectia server

2009-02-03 Thread loial
Has anyone any experiencing with ssh between a python client and the
SSH Tectia server  from SSH (ssh.com) ?

Does it work?



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


Web services

2009-01-26 Thread loial
I am trying to learn about web services and how to interface with a
3rd party web service from python.

Can anyone point me at an idiots guide/tutorial for someone who is new
to web services?

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


Re: sftp with no password from python

2009-01-09 Thread loial
On 8 Jan, 18:49, Mike Hjorleifsson  wrote:
> On Jan 8, 10:39 am, loial  wrote:
>
> > Is it possible to usesftpwithout a password from python?
>
> Yes you can use keys you preestablish between the server and client so
> you dont need passwords, i do this on all my servers then lock off the
> ability to accept passwords at all, this way no one can dictionary
> attack my ssh servers.

Thanks...do you have any python examples of using sftp?

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


sftp with no password from python

2009-01-08 Thread loial
Is it possible to use sftp without a password from python?



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


Re: ssh keepalive

2008-10-02 Thread loial
<>

def command ( self , command ) :
""" process requested command through ssh """
print command
if not self._connected :
return False , "No SSH connection available"
try :
stdin , stdout , stderr =
self._ssh.exec_command( command )
remoteStdOutContent = stdout.readlines()
remoteStdErrContent = stderr.readlines()
if remoteStdErrContent != [] :
return False , '\n'.join(remoteStdErrContent)
return True , '\n'.join(remoteStdOutContent)
except paramiko.SSHException , e :
# provide socket error reason back
return False , str(e)
--
http://mail.python.org/mailman/listinfo/python-list


ssh keepalive

2008-10-01 Thread loial
I have a problem with a ssh connection in python

I get the error

'NoneType' object has no attribute 'exec_command'

I am thinking that maybe the ssh connection is timeing out.

Since I have no control over the configuration of the ssh server(which
is AIX 5.23), is there anything I can do in python to ensure that the
ssh session does not timeout?

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


Re: Question re ConfigParser

2008-08-21 Thread loial
On 20 Aug, 13:49, alex23 <[EMAIL PROTECTED]> wrote:
> On Aug 20, 5:34 pm, loial <[EMAIL PROTECTED]> wrote:
>
> > Given a section like
>
> > [Data]
> > value1
> > value2
> > value3
>
> > Can ConfigParser be easily used to put the values in a dictionary? If
> > so, how?
>
> Dictionaries are key/value pairs. Do you expect 'value1' to be a key
> or a value?
>
> If the data is literally as you describe, and not key/value entries
> (such as 'key1: value1' or 'key1=value1'), you would probably be
> better off just stepping through the file, testing for the [data]
> section and then reading the following lines into a list.

Thanks. Thats what I did in the end
--
http://mail.python.org/mailman/listinfo/python-list


Question re ConfigParser

2008-08-20 Thread loial
Given a section like

[Data]
value1
value2
value3


Can ConfigParser be easily used to put the values in a dictionary? If
so, how?




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


Compare 2 files and discard common lines

2008-05-29 Thread loial
I have a requirement to compare 2 text files and write to a 3rd file
only those lines that appear in the 2nd file but not in the 1st file.

Rather than re-invent the wheel I am wondering if anyone has written
anything already?

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


Delete hidden files on unix

2008-03-03 Thread loial
How can I delete hidden files on unix with python, i.e I want to do
equivalent of

rm  .lock*






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


ftplib.nlst gives error on empty directory

2007-12-07 Thread loial
Trying to use ftplib.FTP.nlst()  method to list the files in
a directory on a FTP server.

It works fine except when there are no files in the directory. Then it
gives the error

ftplib.error_perm: 550 No files found.

How can I handle this cleanly?



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


PYTHONPATH and PYTHON_PATH

2007-12-04 Thread loial
Is there any difference?

Does it matter which I use?

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


Python thinks file is empty

2007-11-05 Thread loial
I am writing a file in python with writelines

f = open('/home/john/myfile',"w")
f.writelines("line1\n")
f.writelines("line2\n")
f.close()

But whenever I try to do anything with the file in python it finds  no
data. I am trying ftp, copying the file...the resultant file is always
0 bytes, although if I look at the original file on the unix command
line, its fine

e.g.

shutil.copyfile('/home/john/myfile', '/home/john/myfile2')


Any ideas what the problem is?

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


variable naming query

2007-07-12 Thread loial
I'ma a newbie python user and would like clarification on variable
naming conventions.

What is the difference between

self.myvariable
self._myvariable
self.__myvariable

and when should I use each of them?

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


How to check if file is in use?

2007-07-10 Thread loial
Is there anyway in pythn to check whether a file is being used/written
to by another process, e.g like the fuser command?

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


install paramiko on AIX (ActiveState)

2007-06-21 Thread loial
I need help installing paramiko on ActiveState python on AIX 5

I am new to python so need info on how to download and install
paramiko

AIX box does not have internet connection so presume cannot use
ez_setup.py?

Can anyone help?

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


Re: Store variable name in another variable

2007-05-01 Thread loial
OK, I have it working with dictionaries.

However I have another scenerio :

I am reading a file containing records like the following :




..
..


I need to substitute MYVARIABLE with the current value of MYVARIABLE
in my python script and write the file out again.

The file may contain many more lines and many substitution values on
any line

Assuming that MYVARIABLE is currently set to JOHN then the output
would be





Can this be done in Python? Amending the way the variable names are
distinguished in the incoming file is possible if that would help.







On 26 Apr, 22:02, Laurent Pointal <[EMAIL PROTECTED]> wrote:
> Cameron Laird wrote:
> > In article <[EMAIL PROTECTED]>,
> > Laurent Pointal  <[EMAIL PROTECTED]> wrote:
> >>loial a ?it :
> >>> I need to store a list ofvariablenames in a dictionary or list. I
> >>> then later need to retrieve the names of the variables and get the
> >>> values from the named variables. The named variables will already have
> >>> been created and given a value.
>
> >>"Named variables will already have been created"... in what namespace ?
>
> >>Store a list of names -> dict/list (see tutorial)
>
> >>Then,
> >>use namespace.name
> >>or  getattr(namespace,"name")
> >>or  locals()["name"]
> >>or  globals()["name"]
>
> > admin, I want to be sure you understand the advice you've been given.
> > Yes, it is possible to "double dereference" through named variables;
> > HOWEVER, it is essentially *never* advantageous to do so in application
> > programming with Python (nor is it in Perl and PHP, despite what many
> > senior people there teach).  Use a dictionary, perhaps one with
> > multi-dimensional keys.
>
> Yes, I understand. I just reply to OP question not searching the reason why
> he wants to manage *variables* this way (he talk about dict, so I hope he
> know that they can be used to map names to values).
> So, this is not an advice, just technical ways related to the question as it
> was written.
>
> And yes, personnally i use dictionnaries for such purpose.
>
> A+
>
> Laurent.- Hide quoted text -
>
> - Show quoted text -


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


Problems with time

2007-05-01 Thread loial
I am running on an AIX system with time zone set to BST

If I run the following, I get the GMT time, i.e an hour less than the
correct time.

How can I get the correct time

now = time()

timeProcessed = strftime("%H:%M",gmtime(now))

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


Store variable name in another variable

2007-04-26 Thread loial
I need to store a list of variable names in a dictionary or list. I
then later need to retrieve the names of the variables and get the
values from the named variables. The named variables will already have
been created and given a value.

I hope thats clear!!!

How can I do this?

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


Problems with os.rename

2007-04-20 Thread loial
I am having problems with os.rename on AIX

The source file definately exists and the target file does not.
However the rename always generates an  OSerror exception.   I can do
the rename via a mv statement at the AIX command line with no problem.

How can I get more info what the cause of the OSError exception is?

N.B. The source file is created by a process run via subprocess e.g.

   from subprocess import Popen, PIPE, STDOUT
   p = Popen(self.command, stdout=PIPE, stderr=STDOUT, shell=True)
   return p.wait()

Could this be the issue?

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


Handling sorted dictionaries

2007-04-17 Thread loial
The following code gives the error

d=sortedmachines[machine]
TypeError: list indices must be integers


What works for the unsorted dictionary does not work for the sorted
dictionary.
Can anyone help?


machinekey = "11"

machines = {}
machines[machinekey]=[1,0,0,0,0,0,0,0,0,0,0,0,0]

machinekey = "22"

machines[machinekey]=[0,1,0,0,0,0,0,0,0,0,0,0,0]

ddd=0
for machine in machines.keys():
   d=machines[machine]
   print machine
   print d [ddd]

sortedmachines=sorted(machines)
for machine in sortedmachines:
  d=sortedmachines[machine]
  print machine
  print d [ddd]

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


Re: More newbie help required with dictionaries

2007-04-16 Thread loial
machines[machinekey] = [0,1,0,0,0,0,0,0,0,0,0,0,0]

is what I needed...thanks



On 16 Apr, 15:07, Christoph Haas <[EMAIL PROTECTED]> wrote:
> On Mon, Apr 16, 2007 at 06:43:37AM -0700, loial wrote:
> > The following code only returns the last row(22) added to the
> > machines dictionary.
> > presumably I need some additional syntax to add rows to the dictionary
> > rather than overwrite.
>
> > What do I need to add?
>
> > machinekey = "11"
>
> > machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] }
>
> > machinekey = "22"
>
> > machines = { machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] }
>
> You redefine the "machines" dictionary here. So it just contains one
> entry. What you mean:
>
> machines.update({ machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] })
>
> Or:
>
> machines[machinekey] = [0,1,0,0,0,0,0,0,0,0,0,0,0]
>
>  Christoph


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


More newbie help required with dictionaries

2007-04-16 Thread loial
The following code only returns the last row(22) added to the
machines dictionary.
presumably I need some additional syntax to add rows to the dictionary
rather than overwrite.

What do I need to add?

machinekey = "11"

machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] }

machinekey = "22"

machines = { machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] }

for machine in machines.keys():
   print machine

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


Re: Newbie help with array handling

2007-04-12 Thread loial
OK, thanks for the replies

One other thing...I need to update the values since they are basically
totals that I am accumulating.

How do I update a specific value for a specific key?


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


  1   2   >