[program-l] Re: Python, Passing a parameter as int instead of STR when using the CMD modual?

  • From: Al Puzzuoli <alpuzz@xxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Tue, 23 Oct 2012 23:10:38 -0400

Hi Richard,
thus far, the particular methods I've been using have only required integers, but as you say, there will be instances where I'll need other types passed, so it would be good to have a smart way of dealing with the issue. For now, I've just been calling the int () function within the methods where I need integers. I've discovered the Pandas library, which is pretty much a Godsend when it comes to this type of work. So basically, I have a method that reads stock data in from Yahoo and returns a DataFrame. This DataFrame is in my main namespace and contains all the information I need in an easily accessible, correctly typed format. my other methods extract slices of data from this dataFrame, so the parameters I'm passing to them are typically slice indexes. For example, one method is called do_range (), and returns the minimum and maximum closing price for the stock within X number of days, and the dates on which those prices occurred.


--Al

On 10/23/2012 10:00 PM, R Dinger wrote:
Hi Al,

I would have to experiment, but you may be able to convert the command tail
string to numbers in the parseline function or as Jim noted in precmd.  I'm
not sure how they would automaticly pass to your function though.

An alternative idea is to have a standard helper routine that your function
calls to convert its tail string in the function.  This could be keyed to
the function name and have a small footprint.  I can give you a short
example if you want.

In either case don't you have to convert to int or float or something else
depending on the parameter?

Richard
----- Original Message -----
From: "Al Puzzuoli" <alpuzz@xxxxxxxxx>
To: "Program L" <program-l@xxxxxxxxxxxxx>
Sent: Tuesday, October 23, 2012 3:02 PM
Subject: [program-l] Python, Passing a parameter as int instead of STR when
using the CMD modual?


I've begun playing with Python's CMD module, and I  now have a
functioning command line interface to my program. I was initially
perplexed though as I was seeing odd errors when executing many of my
methods. Long story short, I realized that this was due to the fact that
CMD passes parameters in as strings, and my functions expected ints.
It's really not a big deal, I can just convert to int within each
method, but it seems there should be a more elegant way to deal with this.

Thanks,

Al

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: