Re: Sandboxing eval()

2020-01-20 Thread Frank
seems quite difficult" I realised that my method is vulnerable to this and, like Robin, I have not come up with an easy way to guard against it. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Line graphics on Linux console

2005-01-29 Thread frank
the lines back for a properly-wri­tten program." I don't really understand the last sentence. Does anyone know if it is possible to do this (or anything else) or am I stuck. TIA for any advice. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

raw_input that able to do detect multiple input

2013-04-06 Thread Frank
Hi all, I would require advise on this question for function call interact: the desire outcome: interact() Friends File: friends.csv Command: f John Cleese John Cleese: Ministry of Silly Walks, 421, 27 October Command: f Michael Palin Unknown friend Michael Palin Command: f Invalid Command: f

Re: raw_input that able to do detect multiple input

2013-04-06 Thread Frank
Hi Dave, Sorry for my unclear question. I didn't use the d = load_friends('friends.csv') now because I'm going use it for other function later on, I should have remove it first to avoid confusion. This is the code for load_friends , add_info ,display_friends, save_friends function: def load_

Re: raw_input that able to do detect multiple input

2013-04-06 Thread Frank
Now you've saved the data in a different file. How does the next run of the program find it? What user? In what environment can a user enter function calls into your code? -The user will call the function out from IDLE Why is the command invalid? -Because the user need to type out a name

How to test if a key in a dictionary exists?

2007-03-10 Thread Frank
cient. I would expect there is something like: name.is_key(name_key) I appreciate your help! Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Formatted Input

2007-03-10 Thread Frank
ew_aux = string.split(aux, ' ') # you can use also other separaters, e.g., \t, or ' more than one space', or... L = len(new_aux) # number of values Remark: the elements in new_aux are string, that means you have to convert them to numbers by,, e.g., int(row[i]). Hope this he

Calling cpp from python/SWIG

2007-03-12 Thread Frank
actly Thanks to all! Frank -- http://mail.python.org/mailman/listinfo/python-list

Calling cpp from python/SWIG

2007-03-12 Thread Frank
! Thanks to all! Frank -- http://mail.python.org/mailman/listinfo/python-list

Calling cpp from python/SWIG

2007-03-13 Thread Frank
! Thanks to all! Frank -- http://mail.python.org/mailman/listinfo/python-list

python/C++ wrapper

2007-03-13 Thread Frank
oblem. If so, could you send me the code, that would be great! If it is important, I use linux and numpy. Thanks, Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: python/C++ wrapper

2007-03-14 Thread Frank
On Mar 14, 1:42 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 14 Mar 2007 01:55:55 -0300, Frank <[EMAIL PROTECTED]> escribió: > > > is there anyone here that calls C++ programs from python via swig? It > > I suggest you read the responses to y

plot dendrogram with python

2007-03-27 Thread Frank
Hi, does anyone know if there is a way to plot a dendrogram with python. Pylab or matplotlib do not provide such a function. Thanks! Frank -- http://mail.python.org/mailman/listinfo/python-list

rpy: parsing arrays from python to R

2007-03-27 Thread Frank
s that one has to do it. Maybe there are people using R with python who have some more experience. I would be interested how they solved this problem. Thanks! Frank -- http://mail.python.org/mailman/listinfo/python-list

plotting R graphics with rpy: figure crashes

2007-03-27 Thread Frank
with sys.version if the python version is the same in both cases (it is). Hence, the problem might be caused by rpy. Has anyone an idea how to figure that out? Thanks! Frank -- http://mail.python.org/mailman/listinfo/python-list

problems loading modules

2007-02-04 Thread Frank
gt; Now everything is back to normal. That means the order the modules are loaded matters! I would expect there is a problem with my installation because I guess this should normally be independent of the loaded modules. Here are my questions: 1. Does anyone has this behavior too? 2. How can I fix

Re: problems loading modules

2007-02-06 Thread Frank
Thanks guys! -- http://mail.python.org/mailman/listinfo/python-list

Saving PyOpenGl figures as ps

2007-02-11 Thread Frank
that. I appreciate every hint! Thanks, Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: numpy, numarray, or numeric?

2007-02-15 Thread Frank
s similar, but the difference is that in numarray the eigenvectors are returned as rows and in numpy as columns. If someone knows of a free manual, let me know. Frank -- http://mail.python.org/mailman/listinfo/python-list

saving path to modules permanently

2007-02-16 Thread Frank
e great to give the precise commands if someone knows how. (BTW, I use linux) Thanks! Frank -- http://mail.python.org/mailman/listinfo/python-list

pyExcelerator: setting zoom of a worksheet

2008-11-25 Thread Frank
-option in Worksheet.py, but it seems not to be there in my version. Anyone ever worked with it and maybe can help me? Thanks a lot. KR, Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Urgent:Serial Port Read/Write

2013-05-09 Thread Frank Miles
On Thu, 09 May 2013 23:35:53 +0800, chandan kumar wrote: > Hi all,I'm new to python and facing issue using serial in python.I'm > facing the below error >     ser.write(port,command)NameError: global name 'ser' is not defined > Please find the attached script and let me know whats wrong in my scri

Re: PDF generator decision

2013-05-14 Thread Frank Miles
On Tue, 14 May 2013 08:05:53 -0700, Christian Jurk wrote: > Hi folks, > > This questions may be asked several times already, but the development > of relevant software continues day-for-day. For some time now I've been > using xhtml2pdf [1] to generate PDF documents from HTML templates (which > a

Question about ast.literal_eval

2013-05-20 Thread Frank Millman
val(b) True >>> from ast import literal_eval >>> literal_eval(b) ValueError: malformed node or string: <_ast.Compare object at ...> Is there a safe way to do what I want? I am using python 3.3. Thanks Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
the string is user-modifiable, so it cannot be trusted. Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
On 20/05/2013 09:55, Chris Angelico wrote: On Mon, May 20, 2013 at 5:50 PM, Frank Millman wrote: On 20/05/2013 09:34, Carlos Nepomuceno wrote: Why don't you use eval()? Because users can create their own columns, with their own constraints. Therefore the string is user-modifiable,

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
SQL injection, which is solved by using parameterised queries. Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
On 20/05/2013 10:07, Frank Millman wrote: On 20/05/2013 09:55, Chris Angelico wrote: Is it a requirement that they be able to key in a constraint as a single string? We have a similar situation in one of the systems at work, so we divided the input into three(ish) parts: pick a field, pick an

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
like the biggest vulnerability concern listed here. Currently, there is no explicit protection against long-running calculations for denial of service attacks. If you're exposing an SQL database to user-generated code, that may be worth considering. Thanks for this, Matt. I will definitely look into it. Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
On 20/05/2013 18:12, Steven D'Aprano wrote: On Mon, 20 May 2013 15:26:02 +0200, Frank Millman wrote: Can anyone see anything wrong with the following approach. I have not definitely decided to do it this way, but I have been experimenting and it seems to work. [...] It seems safe to m

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
On 20/05/2013 18:13, Chris Angelico wrote: On Mon, May 20, 2013 at 11:26 PM, Frank Millman wrote: 0 - for the first entry in the list, the word 'check' (a placeholder - it is discarded at evaluation time), for any subsequent entries the word 'and' or 'or'. 1

Re: Question about ast.literal_eval

2013-05-21 Thread Frank Millman
On 21/05/2013 09:21, Steven D'Aprano wrote: On Tue, 21 May 2013 08:30:03 +0200, Frank Millman wrote: I am not sure I can wrap my mind around mixed 'and's, 'or's, and brackets. Parsers are a solved problem in computer science, he says as if he had a clue what h

Re: Future standard GUI library

2013-06-13 Thread Frank Millman
or no difference whether the client side is running a web browser or a traditional gui interface. On a WAN, there could be a latency problem. Ideally an application should be capable of servicing a local client or a remote client, so it is not easy to find the right balance. Do you have strong

Re: Future standard GUI library

2013-06-13 Thread Frank Millman
"Chris Angelico" wrote in message news:CAPTjJmo+fWsCD3Lb6s+zmWspKzzk_JB=pbcvflbzjgcfxvm...@mail.gmail.com... > On Thu, Jun 13, 2013 at 7:32 PM, Frank Millman wrote: >> I am talking about what I call 'field-by-field validation'. Each field >> could >> h

Re: Future standard GUI library

2013-06-14 Thread Frank Millman
"Chris Angelico" wrote in message news:captjjmq_m4y0uxxt3jqythjj9ckbsvp+z2pgf5v_31xlrgf...@mail.gmail.com... > On Fri, Jun 14, 2013 at 3:39 PM, Frank Millman wrote: >> >> In my case, it is either-or. I do not just do field-by-field validation, >> I >> do

Re: Debugging memory leaks

2013-06-20 Thread Frank Millman
elf._del = DelWatcher(self) Now you can watch the objects as they are created, and then check that they are deleted when you expect them to be. This can help to pinpoint where the memory leak is occurring. HTH Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Default scope of variables

2013-07-09 Thread Frank Millman
ssion instance. When any of them need any database access, whether for reading or for updating, they execute the following - with db_session as conn: conn.transaction_active = True # this line must be added if updating conn.cur.execute(__whatever__) Now it 'just works'. I don't have the need for save-points - either all updates happen, or none of them do. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Default scope of variables

2013-07-09 Thread Frank Millman
"Chris Angelico" wrote in message news:captjjmr4mr0qcgwqxwyvdcz55nuav79vbtt8bjndsdvhrkq...@mail.gmail.com... > On Tue, Jul 9, 2013 at 5:35 PM, Frank Millman wrote: >> I have been following this sub-thread with interest, as it resonates with >> what I am doing in my pr

Re: Default scope of variables

2013-07-09 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzid=fzgjpebifx1stdbkh8iwltwggwwptphz1ykyg+05...@mail.gmail.com... > On Tue, Jul 9, 2013 at 1:35 AM, Frank Millman wrote: >> When any of them need any database access, whether for reading or for >> updating, they execute the f

Re: Default scope of variables

2013-07-09 Thread Frank Millman
. Using your approach, if I mis-spelled 'db_session.connect()', it would immediately raise an error. Is that your concern, or are there other issues? Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Default scope of variables

2013-07-10 Thread Frank Millman
"Ian Kelly" wrote in message news:calwzidk2+b5bym5b+xvtoz8lheyvhcos4v58f8z2o1jb6sa...@mail.gmail.com... > On Tue, Jul 9, 2013 at 11:54 PM, Frank Millman wrote: >> You had me worried there for a moment, as that is obviously an error. >> >> Then I checked my act

Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Frank Millman
I can hack my program to use tobytes(), but it would add complication, and it would be database-specific. I would prefer a cleaner solution. Does anyone have any suggestions? Versions - Python: 3.3.2 PostgreSQL: 9.2.4 psycopg2: 2.5 Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Frank Millman
"Antoine Pitrou" wrote in message news:loom.20130731t114936-...@post.gmane.org... > Frank Millman chagford.com> writes: >> >> I have some binary data (a gzipped xml object) that I want to store in a >> database. For PostgreSQL I use a column with datatype 

Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Frank Millman
"Antoine Pitrou" wrote in message news:loom.20130731t150154-...@post.gmane.org... > Frank Millman chagford.com> writes: >> >> Thanks for that, Antoine. It is an improvement over tobytes(), but i am >> afraid it is still not ideal for my purposes. > > I w

Question about weakref

2012-07-04 Thread Frank Millman
works. So now I am confused. 1. Why do I get the traceback? 2. Can I rely on using weakref.ref, or does that also have some problem that has just not appeared yet? Any advice will be appreciated. BTW, I am using python 3.2.2. Thanks Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about weakref

2012-07-05 Thread Frank Millman
On 05/07/2012 10:46, Dieter Maurer wrote: Frank Millman writes: I have a situation where I thought using weakrefs would save me a bit of effort. Instead of the low level "weakref", you might use a "WeakKeyDictionary". Thanks, Dieter. I could do that. In fact, a WeakS

Re: Question about weakref

2012-07-06 Thread Frank Millman
On 05/07/2012 19:47, Dieter Maurer wrote: Frank Millman writes: I would still like to know why weakref.proxy raised an exception. I have re-read the manual several times, and googled for similar problems, but am none the wiser. In fact, it is documented. Accessing a proxy will raise an

Re: Question about weakref

2012-07-06 Thread Frank Millman
On 06/07/2012 20:12, Ethan Furman wrote: Ian Kelly wrote: def del_b(self, b): for i, x in enumerate(self.array): if b is x: del self.array[i] break Nice work, Ian. I second that. Thanks very much, Ian. Frank -- http://mail.python.org/mailman/listinfo/python-list

Regex Question

2012-08-17 Thread Frank Koshti
Hi, I'm new to regular expressions. I want to be able to match for tokens with all their properties in the following examples. I would appreciate some direction on how to proceed. @foo1 @foo2() @foo3(anything could go here) Thanks- Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Regex Question

2012-08-18 Thread Frank Koshti
to the group. Can anyone help me with the regex? Thanks, Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Regex Question

2012-08-18 Thread Frank Koshti
sn't match $foo by itself, and requires there to be () at the end. Thanks, Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Regex Question

2012-08-18 Thread Frank Koshti
On Aug 18, 11:48 am, Peter Otten <__pete...@web.de> wrote: > Frank Koshti wrote: > > I need to match, process and replace $foo(x=3), knowing that (x=3) is > > optional, and the token might appear simply as $foo. > > > To do this, I decided to use: > > > re.co

Re: Regex Question

2012-08-18 Thread Frank Koshti
On Aug 18, 12:22 pm, Jussi Piitulainen wrote: > Frank Koshti writes: > > not always placed in HTML, and even in HTML, they may appear in > > strange places, such as Hello. My specific issue > > is I need to match, process and replace $foo(x=3), knowing that > > (x=3)

Re: Flexible string representation, unicode, typography, ...

2012-08-25 Thread Frank Millman
is saying that he would have preferred that python standardise on 4-byte characters, on the grounds that the saving in memory does not justify the performance overhead. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Getting ipython notebook to plot inline

2012-10-09 Thread Frank Franklin
I've just managed to install ipython and get it to run by typing ipython notebook --pylab=inline Now I'm getting the following error when I try to plot something in ipython notebook: AttributeError: 'module' object has no attribute 'FigureCanvas' I've tried using imports to make this work:

Re: Getting ipython notebook to plot inline [updated]

2012-10-11 Thread Frank Franklin
ds to do inline plotting. Any help on this would be appreciated -- at this point I'm banging my head against the wall and solution doesn't seem to have surfaced through googling. On Tuesday, October 9, 2012 2:02:17 PM UTC-4, Frank Franklin wrote: > I've just managed to install ip

Re: Organisation of python classes and their methods

2012-11-02 Thread Frank Millman
f, ...): [...] def func2(self, ...): [...] AFTER = setup.py - def setup1(self, ...): [...] def setup2(self, ...): [...] main.py - import setup class MyClass: setup1 = setup.setup1 setup2 = setup.setup2 def func1(self, ...): [...] def fun

Re: MySQLdb compare lower

2012-12-13 Thread Frank Millman
name) = LOWER(%s), and it will use the index, so it is not necessary to coerce the data to lower case before storing. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

py2exe is on Sourceforge list of top growth projects

2012-12-17 Thread Frank Millman
th in the last month. [...] py2exe: A distutils extension to create standalone Windows programs from python scripts. It is 19th on a list of 19, but still, it is nice to see. I wonder if there was any particular reason for that? Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Need a specific sort of string modification. Can someone help?

2013-01-05 Thread Frank Millman
think is correct - there are 4 dots in the original string. HTH Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Else statement executing when it shouldnt

2013-01-25 Thread Frank Millman
d it, you want to do something and break. If you do not find it, you want to do something else. for item in iterable: if item == 'something': do_something() break else: # item was not found do_something_else() Not arguing for or against, just saying it is di

Re: ??????????? DOES GOG EXIST

2013-01-26 Thread Frank Millman
On 26/01/2013 18:41, BV BV wrote: DOES GOG EXIST http://www.youtube.com/watch?v=tRMmTbCXXAk&feature=related THANK YOU Did you hear about the dyslexic agnostic insomniac? He lies awake at night wondering if there is a dog. -- http://mail.python.org/mailman/listinfo/python-list

Sorting a hierarchical table (SQL)

2013-01-30 Thread Frank Millman
depth of more than 4 or 5, so I can live with it. However, it is not pretty. I wondered if anyone can suggest a more elegant solution. Thanks Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Distributing methods of a class across multiple files

2012-01-25 Thread Frank Millman
py - import test2 class Foo: long_method_1 = test2.long_method_1 long_method_2 = test2.long_method_2 Then in Foo I can refer to self.long_method_1(). HTH Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: constraint based killer sudoku solver performance improvements

2012-01-26 Thread Frank Millman
it in the blink of an eye. It also outputs a full trace of the reasoning it used to arrive at a solution. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and TAP

2012-02-06 Thread Frank Becker
of-tap-test-anything-protocol-and-subunit/ [2] http://pyyaml.org/ [3] http://testanything.org/wiki/index.php/YAMLish Bye, Frank -- Frank Becker (jabber|mail) | http://twitter.com/41i3n8 GnuPG: 0xADC29ECD | F01B 5E9C 1D09 981B 5B40 50D3 C80F 7459 ADC2 9ECD signature.asc De

Question about circular imports

2012-02-26 Thread Frank Millman
f that makes any difference. Any advice will be appreciated. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about circular imports

2012-02-26 Thread Frank Millman
"Frank Millman" wrote in message news:jid2a9$n21$1...@dough.gmane.org... > Hi all > > I seem to have a recurring battle with circular imports, and I am trying > to nail it once and for all. > [...] > > The second solution is - > > in formats/__init__.py &

Re: Question about circular imports

2012-02-26 Thread Frank Millman
"Peter Otten" <__pete...@web.de> wrote in message news:jid424$vfp$1...@dough.gmane.org... > Frank Millman wrote: > > > To cut a long story short, why should circular imports be unavoidable? > > Paths into packages are recipe for desaster. You may end up wit

Re: Question about circular imports

2012-02-26 Thread Frank Millman
File "F:\tests\b\d.py", line 2, in c = b.c AttributeError: 'module' object has no attribute 'c' I get the same if I try 'import b.c as c'. Frank -- http://mail.python.org/mailman/listinfo/python-list

Question about sub-packages

2012-02-27 Thread Frank Millman
hen place calls on it directly. I did a quick test and it seems to work. Is this a good idea, or are there any downsides? Thanks Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about sub-packages

2012-02-28 Thread Frank Millman
"Frank Millman" wrote in message news:jii0vo$36t$1...@dough.gmane.org... > Hi all > > This is a follow-up to my recent question about circular imports, but on a > different subject, hence the new thread. > [...] > > If this makes sense, my next thought was,

Trying to understand 'import' a bit better

2012-03-04 Thread Frank Millman
ported twice under different names, with potentially disastrous consequences. Therefore, as I see it, if you are developing a project using scenario 1 above, and then want to change it to scenario 2, you have to go through the entire project and change all import references by prepending the package name. Have I got this right? Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading Live Output from a Subprocess

2012-04-06 Thread Frank Millman
- the digits 0 to 4 displayed with delays of 1 second. Running sub_proc2 gives exactly the same output. This is using python 3.2.2 on Windows Server 2003. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Difference between 'imp' and 'importlib'

2012-04-20 Thread Frank Millman
also works, and does not reload the module. So my question is, is there any practical difference between the two approaches? What about 'There should be one-- and preferably only one --obvious way to do it'? Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Strange __import__() behavior

2012-04-25 Thread Frank Miles
I have an exceedingly simple function that does a "named import". It works perfectly for one file "r"- and fails for the second "x". If I reverse the order of being called, it is still "x" that fails, and "r" still succeeds. os.access() always reports that the file is readable (i.e. "true") If I

Re: Strange __import__() behavior

2012-04-26 Thread Frank Miles
On Wed, 25 Apr 2012 23:03:36 +0200, Kiuhnm wrote: > On 4/25/2012 22:05, Frank Miles wrote: >> I have an exceedingly simple function that does a "named import". It >> works perfectly for one file "r"- and fails for the second "x". >> >> If

Minor issue with sqlite3 and datetime

2012-04-29 Thread Frank Millman
is - microseconds = int('{:0<6}'.format(timepart_full[1])) Any chance of this being accepted? Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Some posts do not show up in Google Groups

2012-04-29 Thread Frank Millman
OE, so they are being accepted. I send to the group gmane.comp.python.general. Does anyone know a reason for this, or have a solution? Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Some posts do not show up in Google Groups

2012-04-30 Thread Frank Millman
On Apr 30, 8:20 am, Frank Millman wrote: > Hi all > > For a while now I have been using Google Groups to read this group, but on > the odd occasion when I want to post a message, I use Outlook Express, as I > know that some people reject all messages from Google Groups due to t

OT, but very funny

2011-06-29 Thread Frank Millman
out of cookie use, now web site operators need to ask for permission before they implement any cookies. So the opt out system has been replaced with an opt in system. Enjoy Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

test

2011-06-30 Thread Frank Müller
something to test? -- http://mail.python.org/mailman/listinfo/python-list

Re: subprocess & isql

2011-07-15 Thread Frank Millman
reading.Thread(target=read_stdout, args=(sql_stdout,)).start() s.seek(0) sql_stdin.writelines(s.readlines()) s.close() sql_stdin.close() HTH Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Convert '165.0' to int

2011-07-21 Thread Frank Millman
rst, it does work - int(float(x)) 165 Is there a short cut, or must I do this every time (I have lots of them!) ? I know I can write a function to do this, but is there anything built-in? Thanks Frank Millman -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert '165.0' to int

2011-07-21 Thread Frank Millman
On Jul 21, 11:47 am, Leo Jay wrote: > On Thu, Jul 21, 2011 at 5:31 PM, Frank Millman wrote: > > > Hi all > > > I want to convert '165.0' to an integer. > > > The obvious method does not work - > > >>>> x = '165.0' > >&g

Re: Convert '165.0' to int

2011-07-21 Thread Frank Millman
On Jul 21, 11:53 am, Thomas Jollans wrote: > On 21/07/11 11:31, Frank Millman wrote: > > > Hi all > > > I want to convert '165.0' to an integer. > > Well, it's not an integer. What does your data look like? How do you > wish to convert it to int?

Re: Convert '165.0' to int

2011-07-21 Thread Frank Millman
per loop C:\Python32\Lib>timeit.py "int('165.0'[:-2])" 10 loops, best of 3: 4.63 usec per loop Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert '165.0' to int

2011-07-21 Thread Frank Millman
ble for python to accept int('165.0') and return 165. I would expect it to raise an exception if there were any non-zero digits after the point. However, the fact is that python does not accept this, and I am not asking for a change. int(float(x)) does the job, and I am happy with that. I was just asking if there were any alternatives. Frank -- http://mail.python.org/mailman/listinfo/python-list

Question about timeit

2011-07-21 Thread Frank Millman
("165.0"))' 1000 loops, best of 3: 0.0887 usec per loop I ran them both twice just to be sure. The first two use double-quote marks to surround the statement, and single-quote marks to surround the literal inside the statement. The second two swap the quote marks around.

Re: Question about timeit

2011-07-22 Thread Frank Millman
On Jul 22, 8:37 am, Stefan Behnel wrote: > Frank Millman, 22.07.2011 08:06: > > > > > > > I mentioned in a recent post that I noticed an inconsistency in timeit, and > > then reported that I must have made a mistake. > > > I have now identified my prob

Re: Question about timeit

2011-07-22 Thread Frank Millman
On Jul 22, 10:34 am, Stefan Behnel wrote: > Thomas Rachel, 22.07.2011 10:08: > > > > > > > Am 22.07.2011 08:59 schrieb Frank Millman: > > >> My guess is that it is something to do with the console, but I don't > >> know what. If I get time over t

Re: Question about timeit

2011-07-22 Thread Frank Millman
On Jul 22, 2:43 pm, Thomas Jollans wrote: > On 22/07/11 14:30, Frank Millman wrote: > > > > > > > This is what I get after modifying timeit.py as follows - > > >     if args is None: > >         args = sys.argv[1:] > > +       print(args) > > &

Re: Convert '165.0' to int

2011-07-22 Thread Frank Millman
On Jul 22, 9:59 pm, Terry Reedy wrote: > On 7/22/2011 1:55 AM, Frank Millman wrote: > > > As the OP, I will clarify what *my* requirement is. This discussion > > has gone off at various tangents beyond what I was asking for. > > Typical. Don't worry about it ;-). &

Re: Convert '165.0' to int

2011-07-23 Thread Frank Millman
On Jul 23, 9:42 am, Chris Angelico wrote: > On Sat, Jul 23, 2011 at 4:53 PM, Frank Millman wrote: > > The problem with that is that it will silently ignore any non-zero > > digits after the point. Of course int(float(x)) does the same, which I > > had overlooked. > >

Re: Convert '165.0' to int

2011-07-23 Thread Frank Millman
On Jul 23, 10:23 am, Steven D'Aprano wrote: > Frank Millman wrote: > > To recap, the original problem is that it would appear that some third- > > party systems, when serialising int's into a string format, add a .0 > > to the end of the string. I am trying

Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
t; > -- > Bill True enough. If I really wanted to be 100% safe, how about this - def get_int(s): if '.' in s: num, dec = s.split('.', 1) if dec != '': if int(dec) != 0: raise ValueError('

Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 24, 9:34 am, Steven D'Aprano wrote: > Frank Millman wrote: > > If I really wanted to be 100% safe, how about this - > > >     def get_int(s): > >         if '.' in s: > >             num, dec = s.split('.', 1) > >  

Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 24, 10:07 am, Chris Angelico wrote: > On Sun, Jul 24, 2011 at 5:58 PM, Frank Millman wrote: > >  if int(dec) != 0: > > to > >    if [_ for _ in list(dec) if _ != '0']: > > if dec.rtrim('0')!='': > > ChrisA I think you mean

Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 23, 8:28 pm, rantingrick wrote: > On Jul 23, 1:53 am, Frank Millman wrote: > > >-- > > The ideal solution is the one I sketched out earlier - modify python's > > 'int' fu

Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 24, 10:53 am, Ben Finney wrote: > Frank Millman writes: > > I know I am flogging a dead horse here, but IMHO, '165', '165.', > > '165.0', and '165.00' are all valid string representations of the > > integer 165.[1] > &g

  1   2   3   4   5   6   7   8   9   10   >