Working with XML/XSD

2013-08-05 Thread David Barroso
Hello, I was wondering if someone could point me in the right direction. I would like to develop some scripts to manage Cisco routers and switches using XML. However, I am not sure where to start. Does someone have some experience working with XML, Schemas and things like that? Which libraries do y

Re: Newbie: static typing?

2013-08-05 Thread Steven D'Aprano
On Mon, 05 Aug 2013 21:46:57 +0100, Rui Maciel wrote: > Is there any pythonic way to perform static typing? After searching the > web I've stumbled on a significant number of comments that appear to > cover static typing as a proof of concept , but in the process I've > found no tutorial on how t

Re: Hangman question

2013-08-05 Thread eschneider92
Thanks I get it now. -- http://mail.python.org/mailman/listinfo/python-list

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23
On 6/08/2013 1:49 PM, alex23 wrote: On 6/08/2013 1:12 PM, Joshua Landau wrote: Because it's bad to open files without a with unless you know what you're doing, use a with: with open('/home/collier/pytest/__sort.TXT') as file: sorted(file, key=str.casefold, reverse=True) Shouldn'

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23
On 6/08/2013 1:49 PM, alex23 wrote: Shouldn't that be: with open('/home/collier/pytest/__sort.TXT') as file: data = file.readlines() sorted(data, key=str.casefold, reverse=True) I'm tempted to say "HINT #5: don't provide a solution without testing it first" but that would

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23
On 6/08/2013 1:12 PM, Joshua Landau wrote: Because it's bad to open files without a with unless you know what you're doing, use a with: with open('/home/collier/pytest/__sort.TXT') as file: sorted(file, key=str.casefold, reverse=True) Shouldn't that be: with open('/home/coll

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread edu4madh
On Monday, August 5, 2013 10:00:55 PM UTC-4, Devyn Collier Johnson wrote: > I am wanting to sort a plain text file alphanumerically by the lines. I > > have tried this code, but I get an error. I assume this command does not > > accept newline characters. > > > > > > >>> file = open('/hom

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread Joshua Landau
On 6 August 2013 03:00, Devyn Collier Johnson wrote: > I am wanting to sort a plain text file alphanumerically by the lines. I > have tried this code, but I get an error. I assume this command does not > accept newline characters. > HINT #1: Don't assume that without a reason. It's wrong. > >>>

Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread MRAB
On 06/08/2013 03:00, Devyn Collier Johnson wrote: I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume this command does not accept newline characters. >>> file = open('/home/collier/pytest/sort.TXT', 'r').read() That ret

Re: Creating a running tally/ definitely new to this

2013-08-05 Thread Dave Angel
gratedme...@gmail.com wrote: > > I currently working on a game, where I need to maintain a running tally of > money, as the player makes purchases as they navigate thru game. I not > exactly sure how to do this in python. I know it is a fairly basic step, > nonetheless. Any assistance would

Re: Creating a running tally/ definitely new to this

2013-08-05 Thread Joshua Landau
On 6 August 2013 02:01, wrote: > > I currently working on a game, where I need to maintain a running tally of > money, as the player makes purchases as they navigate thru game. I not > exactly sure how to do this in python. I know it is a fairly basic step, > nonetheless. Any assistance would

Sort lines in a plain text file alphanumerically

2013-08-05 Thread Devyn Collier Johnson
I am wanting to sort a plain text file alphanumerically by the lines. I have tried this code, but I get an error. I assume this command does not accept newline characters. >>> file = open('/home/collier/pytest/sort.TXT', 'r').read() >>> print(file) z c w r h s d >>> file.sort() #The first bl

Creating a running tally/ definitely new to this

2013-08-05 Thread gratedmedia
I currently working on a game, where I need to maintain a running tally of money, as the player makes purchases as they navigate thru game. I not exactly sure how to do this in python. I know it is a fairly basic step, nonetheless. Any assistance would be greatly appreciated. -- http://m

Re: Newbie: static typing?

2013-08-05 Thread Ben Finney
Rui Maciel writes: > Is there any pythonic way to perform static typing? I think no; static typing is inherently un-Pythonic. Python provides strong, dynamic typing. Enjoy it! > Does anyone care to enlighten a newbie? Is there some specific problem you think needs static typing? Perhaps you c

Re: Newbie: static typing?

2013-08-05 Thread Ian Kelly
On Mon, Aug 5, 2013 at 2:46 PM, Rui Maciel wrote: > Is there any pythonic way to perform static typing? After searching the web > I've stumbled on a significant number of comments that appear to cover > static typing as a proof of concept , but in the process I've found no > tutorial on how to im

Re: PyArg_ParseTuple() when the type could be anything?

2013-08-05 Thread David M. Cotter
i was able to get what i wanted by simply iterating over the tupile instead of using ParseTupile, then just query the type, then convert the type to C and move on to the next. totally great, now i can pass N different argument types to a single function, and have the C side deal gracefully with

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB
On 05/08/2013 22:47, Luca Cerone wrote: You're back to using separate threads for the reader and the writer. And how do I create separate threads in Python? I was trying to use the threading library without not too success.. To run a function in a separate thread: import threading def my_f

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Francois Lafont
Le 05/08/2013 22:01, Rafael Durán Castañeda a écrit : > I think you are looking for exclusive groups: > > http://docs.python.org/2.7/library/argparse.html#argparse.add_mutually_exclusive_group Yes... but no. The doc explains you can do this: my-script (-b VALUE-B | -d VALUE-D) ie mutally excl

Re: undefined method []' for nil:NilClass (NoMethodError)

2013-08-05 Thread Chris Angelico
On Mon, Aug 5, 2013 at 11:24 PM, wrote: > I have this script to monitor solr4 with munin. > > But I get an error and I hove no idea what's the problem. > > Error: > /etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:60: undefined method > []' for nil:NilClass (NoMethodError) > > cores_url =

undefined method []' for nil:NilClass (NoMethodError)

2013-08-05 Thread thcerbla . netsrot
Hi, I have this script to monitor solr4 with munin. But I get an error and I hove no idea what's the problem. Hope someone can help me... Thanks, Torsten Error: /etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:60: undefined method []' for nil:NilClass (NoMethodError) from /etc/munin/

RE: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Joseph L. Casale
> I think you are looking for exclusive groups: > > http://docs.python.org/2.7/library/argparse.html#argparse.add_mutually_excl > usive_group No. That links first doc line in that method shows the very point we are all discussing: "Create a mutually exclusive group. argparse will make sure that

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Francois Lafont
Le 05/08/2013 16:11, Miki Tebeka a écrit : > You can probably do something similar using sub commands > (http://docs.python.org/2/library/argparse.html#sub-commands). Yes, but this is not the same syntax. I want this syntax : my-script (-a -b VALUE-B | -c -d VALUE-D) I don't want this syntax:

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
> You're back to using separate threads for the reader and the writer. > And how do I create separate threads in Python? I was trying to use the threading library without not too success.. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie: static typing?

2013-08-05 Thread Gary Herron
On 08/05/2013 01:46 PM, Rui Maciel wrote: Is there any pythonic way to perform static typing? After searching the web I've stumbled on a significant number of comments that appear to cover static typing as a proof of concept , but in the process I've found no tutorial on how to implement it. Do

Newbie: static typing?

2013-08-05 Thread Rui Maciel
Is there any pythonic way to perform static typing? After searching the web I've stumbled on a significant number of comments that appear to cover static typing as a proof of concept , but in the process I've found no tutorial on how to implement it. Does anyone care to enlighten a newbie? T

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Rafael Durán Castañeda
El 04/08/13 04:10, Francois Lafont escribió: Hi, Is it possible with argparse to have this syntax for a script? my-script (-a -b VALUE-B | -c -d VALUE-D) I would like to do this with the argparse module. Thanks in advance. I think you are looking for exclusive groups: http://docs.python.o

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB
On 05/08/2013 17:54, Luca Cerone wrote: Thanks this works (if you add shell=True in Popen). If I don't want to use shell = True, how can I redirect the stdout to named_pipe? Popen accepts an open file handle for stdout, which I can't open for writing because that blocks the process... You're

Module for dialoging with intercative programs, sockets, files, etc.

2013-08-05 Thread Olive
I have found telnetlib which make very easy to interact with a telnet server, especially the read_until command. I wonder if something similar exits for other things that a telnet server. I for the moment have in mind interacting with a GSM modem (we do it by reading and writing a pseudo serial

Re: Piping processes works with 'shell = True' but not otherwise.

2013-08-05 Thread Tobiah
On 05/27/2013 04:33 AM, Luca Cerone wrote: Will it violate privacy / NDA to post the command line? Even if we can't actually replicate your system, we may be able to see something from the commands given. Unfortunately yes.. p1 = Popen(['nsa_snoop', 'terror_suspect', '--no-privacy', '-

RE: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Joseph L. Casale
> You can probably do something similar using sub commands > (http://docs.python.org/2/library/argparse.html#sub-commands). The problem here is that argparse does not pass the subparser into the parsed args and shared args between subparsers need to be declared each time. Come execution time, when

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Thanks this works (if you add shell=True in Popen). If I don't want to use shell = True, how can I redirect the stdout to named_pipe? Popen accepts an open file handle for stdout, which I can't open for writing because that blocks the process... > > > os.mkfifo("named_pipe", 0777) > > ls_proc

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Neil Cerutti
On 2013-08-05, Luca Cerone wrote: > I just would like to learn how to handle named pipes in Python, > which I find it easier to do by using a simple example that I > am comfortable to use :) Names pipes are a unix concept that saves you the hassle and limitations of writing to and reading from a

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB
On 05/08/2013 16:27, Luca Cerone wrote: Thanks MRAB, You need to ensure that the pipe is already open at the other end. So I need to open the process that reads the pipe before writing in it? Why are you using a named pipe anyway? For some bug in ipython (see my previous email) I can't u

Re: Piping processes works with 'shell = True' but not otherwise.

2013-08-05 Thread Luca Cerone
thanks and what about python 2.7? > > > In Python 3.3 and above: > > > > p = subprocess.Popen(..., stderr=subprocess.DEVNULL) P.s. sorry for the late reply, I discovered I don't receive notifications from google groups.. -- http://mail.python.org/mailman/listinfo/python-list

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Thanks MRAB, > > You need to ensure that the pipe is already open at the other end. So I need to open the process that reads the pipe before writing in it? > > > > Why are you using a named pipe anyway? For some bug in ipython (see my previous email) I can't use subprocess.Popen and pipe in

Re: Bug? ( () == [] ) != ( ().__eq__([]) )

2013-08-05 Thread Ian Kelly
On Mon, Aug 5, 2013 at 8:58 AM, Markus Rother wrote: > Thanks for the good explanation. > > My intention was to pass a custom method/function as a comparator > to an object. My misconception was, that __eq__ is equivalent to > the '==' operator, and could be passed as a first class function. > Ap

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi Alister, > Are you sure you are using the correct tool for the task? Yes. For two reasons: 1. I want to learn how to do this in Python :) 2. for an application I have in mind I will need to run external tools (not developed by me) and process the output using some tools that I have written in

Re: Bug? ( () == [] ) != ( ().__eq__([]) )

2013-08-05 Thread Markus Rother
Thanks for the good explanation. My intention was to pass a custom method/function as a comparator to an object. My misconception was, that __eq__ is equivalent to the '==' operator, and could be passed as a first class function. Apparently, that is not possible without wrapping the comparison i

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB
On 05/08/2013 15:11, Luca Cerone wrote: Hi MRAB, thanks for the reply! Opening the pipe for reading will block until it's also opened for writing, and vice versa. OK. In your bash code, 'ls' blocked until you ran 'cat', but because you ran 'ls' in the background you didn't notice it! R

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Alister
On Mon, 05 Aug 2013 06:09:53 -0700, Luca Cerone wrote: > Hi everybody, > I am trying to understand how to use named pipes in python to launch > external processes (in a Linux environment). > > As an example I am trying to "imitate" the behaviour of the following > sets of commands is bash: > >>

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Miki Tebeka
> Is it possible with argparse to have this syntax for a script? > my-script (-a -b VALUE-B | -c -d VALUE-D) > > I would like to do this with the argparse module. You can probably do something similar using sub commands (http://docs.python.org/2/library/argparse.html#sub-commands). -- http://mai

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi MRAB, thanks for the reply! > > Opening the pipe for reading will block until it's also opened for > > writing, and vice versa. > OK. > > > In your bash code, 'ls' blocked until you ran 'cat', but because you > > ran 'ls' in the background you didn't notice it! > > Right. > > In your

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB
On 05/08/2013 14:09, Luca Cerone wrote: Hi everybody, I am trying to understand how to use named pipes in python to launch external processes (in a Linux environment). As an example I am trying to "imitate" the behaviour of the following sets of commands is bash: mkfifo named_pipe ls -lah >

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi Paul, first of all thanks for the help. I am aware of the first solutions, just now I would like to experiment a bit with using named pipes (I also know that the example is trivial, but it just to grasp the main concepts) > > You can also pass a file object to p1's stdout and p2's stdin if

Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Paul Wiseman
On 5 August 2013 14:09, Luca Cerone wrote: > Hi everybody, > I am trying to understand how to use named pipes in python to launch > external processes (in a Linux environment). > > As an example I am trying to "imitate" the behaviour of the following sets > of commands is bash: > > > mkfifo named

Re: Simple Python script as SMTP server for outgoing e-mails?

2013-08-05 Thread Sanjay Arora
On Tue, Jul 23, 2013 at 2:49 PM, Chris Angelico wrote: > Ah, there's a solution to this one. You simply use your own > envelope-from address; SPF shouldn't be being checked for the From: > header. Forwarding and using the original sender's address in the SMTP > 'MAIL FROM' command is forging mai

Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi everybody, I am trying to understand how to use named pipes in python to launch external processes (in a Linux environment). As an example I am trying to "imitate" the behaviour of the following sets of commands is bash: > mkfifo named_pipe > ls -lah > named_pipe & > cat < named_pipe In Pyt

Re: __iadd__ for a subclass of array - howto

2013-08-05 Thread Ian Kelly
On Mon, Aug 5, 2013 at 1:34 AM, Helmut Jarausch wrote: > Hi, > > I'd like to subclass array.array and implement operators like __iadd__ > How can this be accomplished. > > I'tried > > from array import array > > class Vec(array) : > def __new__(cls,Vinit) : > return array.__new__(cls,'d',Vin

__iadd__ for a subclass of array - howto

2013-08-05 Thread Helmut Jarausch
Hi, I'd like to subclass array.array and implement operators like __iadd__ How can this be accomplished. I'tried from array import array class Vec(array) : def __new__(cls,Vinit) : return array.__new__(cls,'d',Vinit) def __init__(self,*args) : self.N = len(self) def __str__(self

Re: stupid simple scope issue

2013-08-05 Thread JohnD
On 2013-08-04, Chris Angelico wrote: > On Sun, Aug 4, 2013 at 8:21 PM, JohnD wrote: >> On 2013-08-04, Chris Angelico wrote: [...] > > Python does have a slightly odd (compared to other languages) > interpretation of "variable assignments" (name bindings, really) > inside a class block. Trips up

Re: outputting time in microseconds or milliseconds

2013-08-05 Thread Ulrich Eckhardt
Am 02.08.2013 15:17, schrieb matt.doolittl...@gmail.com: so you are saying that self.logfile.write('%s\t'%(str(time( should be: self.logfile.write('%s\t'%(str(time.time( No, I'm not saying that. What I wanted to make clear is that your code is impossible to understand as it