Re: Help with Python/ArcPy

2012-12-12 Thread Xavier Ho
You can always try http://stackoverflow.com/search?q=ArcPY, or post your question there. Cheers, Xav On 13 December 2012 08:07, Michelle Couden wrote: > Does anyone know of a website or forum where there is help for ArcPY > (Python) programmers? ESRI’s (GIS) resource center Forums are very b

Python 2 multiprocessing examples in docs.python.org

2013-01-31 Thread Xavier Ho
Hey all, I ran the example code on multiprocessing. On the "Pool example", an assertion failed with "testing garbage collection". Traceback (most recent call last): File "test.py", line 314, in test() File "test.py", line 295, in test assert not worker.is_alive() AssertionError The

Re: Upgrading from 2.7 to 3.x

2012-04-25 Thread Xavier Ho
What operating system are you running? Cheers, Xav On 26 April 2012 13:08, deuteros wrote: > I'm fairly new to Python I have version 2.7 installed on my computer. > However > my professor wants us all to use the latest version of Python. How do I go > about upgrading? Do I just install the ne

Re: Fun python 3.2 one-liner

2011-03-29 Thread Xavier Ho
http://www.ideone.com/infch ^ Result of the below code On 29 March 2011 19:50, Raymond Hettinger wrote: > from collections import Counter > from itertools import product > > print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum, > product(range(6), repeat=8))).items( > > > almost-n

Re: [OT] Awesome bug of the week

2014-08-13 Thread Xavier Ho
Haha! On 14 August 2014 14:54, Steven D'Aprano wrote: > Nothing to do with Python, but awesome: "OpenOffice won't print on > Tuesdays". > > https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/255161/comments/28 > > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list >

Re: Execute a command on remote machine in python

2011-11-15 Thread Xavier Ho
It sounds like Fabric is what you're after. We use it at work and it's the best thing since ssh. ;] http://docs.fabfile.org/en/1.3.2/index.html (Actually, it uses ssh internally and allows you to do remote shell-like programming in a pythonic fashion.) Cheers, Xav On 15 November 2011 22:04, R

Comparing None and ints

2012-01-16 Thread Xavier Ho
Hello, I discovered this strange property by accident: Python 2.7.2 (default, Nov 21 2011, 17:25:27) [GCC 4.6.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> None < 0 True >>> None == 0 False >>> None > 0 False >>> int(None) Traceback (most recent call last

Re: Comparing None and ints

2012-01-16 Thread Xavier Ho
Good to see Python3 got rid of that confusion :] Cheers, Xav On 17 January 2012 16:50, Chris Angelico wrote: > On Tue, Jan 17, 2012 at 5:47 PM, Xavier Ho wrote: > > What was the rationale behind this design? Specifically, (None < 0) == > True > > and

Fwd: Recording live video stream from IP camera issue

2013-02-06 Thread Xavier Ho
On 6 February 2013 23:12, Sam Berry wrote: > I have no vast knowledge of python, but i came across this code to capture > video from my IP camera > > This code works, however when i try to playback the .avi file in VLC > player... I've been working with several IP cameras with Python and OpenCV

Re: Recording live video stream from IP camera issue

2013-02-06 Thread Xavier Ho
On 7 February 2013 00:12, Sam Berry wrote: > Hi, > > This is for a university project. > > My issue is that i have built an App using pythons Kivy module, and i need > to be able to stream and record from an IP camera upon request. > > I have just used the VLC.exe to stream the video feed. But it

Re: Recording live video stream from IP camera issue

2013-02-17 Thread Xavier Ho
Hi Sam, Did you compile your OpenCV with gstreamer? That's where I'd look first. Cheers, Xav On 18 February 2013 01:15, Sam Berry wrote: > Hi Xav, > > Iv been looking into OpenCV, i can easily stream my laptops webcam using > this code. > > import cv2 > > cv2.namedWindow("preview") > > vc =

Re: how do you make a loop run in reverse?

2013-03-26 Thread Xavier Ho
There is a built-in function that reverses an iterable. Have a look at the documentation. xav On 27 March 2013 10:59, wrote: > So i have a set of for loops that create this : > > *** > *** *** *** *** *** *** *** > *** *** *** *** ***

Re: Functional vs. Object oriented API

2013-04-10 Thread Xavier Ho
Hi Max, In Python, we prefer readability over anything else. The simpler you can write it, the better it can be understood. That said, I've never considered using (i, j, k) as a vector component before. I've always done something akin to: >>> vector = Vector(2, 4, 6) >>> print (vector.normaliz

Re: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2009-12-07 Thread Xavier Ho
Hi Victor, the .append function doesn't return anything, so it's a None. And you should have it inside the parentheses. >>> tree.append("%s%s" % ("\t" * level, name)) is probably what you're after. Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Overriding the >> builtin

2009-12-11 Thread Xavier Ho
On Fri, Dec 11, 2009 at 12:05 PM, Kevin Ar18 wrote: > I am aware of the fact that you can somehow replace the __builtins__ in > Python. There is a library here that modifies the >> binary builtins: > http://github.com/aht/stream.py/blob/master/stream.py > > Question: Is there anywhere that expl

Re: Class variables static by default?

2009-12-19 Thread Xavier Ho
Yes, if you want instance variables that are unique to each instance of a class, do the following: class Parser: def __init__(self): self.items = [] And that should work fine. J:\_Programming Projects\Python>python test.py <__main__.Parser object at 0x0240E7B0> <__main__.Parser object

Re: Invalid syntax error

2009-12-20 Thread Xavier Ho
Putting quotemarks "" around the path would be a good start, I think. Cheers, Xav On Sun, Dec 20, 2009 at 11:40 PM, Ray Holt wrote: > Why am I getting an invalid syntax error on the following: > os.chdir(c:\\Python_Modules). The error message says the colon after c is > invalid syntax. Why is

Re: a=[1,2,3,4].reverse() - why "a" is None?

2009-10-12 Thread Xavier Ho
Nadav, it's because reverse() modifies the list in-place. I've gotten this gotcha many times, If you had done: >>> a = [1,2,3,4] >>> a.reverse() >>> a [4, 3, 2, 1] Or even better: >>> a = [1,2,3,4][::-1] >>> a [4, 3, 2, 1] Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: The rap against "while True:" loops

2009-10-12 Thread Xavier Ho
On Mon, Oct 12, 2009 at 11:32 PM, Luis Zarrabeitia wrote: > Actually, in python, this works even better: > > for lin in iter(file_object.readline, ""): >... do something with lin > > What about >>> with open(path_string) as f: >>> for line in f: >>> # do something Cheers, X

Re: What command should be use when the testing of arguments is failed?

2009-10-14 Thread Xavier Ho
On Thu, Oct 15, 2009 at 10:58 AM, Peng Yu wrote: > I actually wanted to ask what return code should be returned in this > case when the arguments are not right. Thank you1 > > I think that depends on the design of the program. Is there a return value that would make sense to be returned by defaul

Re: () vs. [] operator

2009-10-15 Thread Xavier Ho
On Thu, Oct 15, 2009 at 5:14 PM, Ole Streicher wrote: > So what is the reason that Python has separate __call__()/() and > __getitem__()/[] interfaces and what is the rule to choose between them? Hi, This is very interesting, a thought that never occured to me before. Usually, a function is a

Re: () vs []

2009-10-15 Thread Xavier Ho
On Thu, Oct 15, 2009 at 3:21 AM, Nanjundi wrote: > 3 You can’t find elements in a tuple. Tuples have no index method. > I don't know what language you're using there, but my Python tuples have indexes. >>> a = (1, 2, 3) >>> a (1, 2, 3) >>> a[1] 2 -- http://mail.python.org/mailman/listinf

Re: () vs []

2009-10-15 Thread Xavier Ho
On Thu, Oct 15, 2009 at 6:39 PM, Chris Rebert wrote: > Nanjundi meant "index method" as in "a method .index()" (i.e. a method > named "index") which searches through the container for the given item > and returns the index of the first instance of said item, like > list.index() does. > > Interest

Re: () vs []

2009-10-15 Thread Xavier Ho
On Thu, Oct 15, 2009 at 6:55 PM, Tim Golden wrote: > It was added relatively recently, around Python 2.6 I think, > at least partly as an oh-ok-then reaction to everyone asking: > "how come lists have .index and .count and tuples don't?" > and neverending "tuples-are-immutable-lists-no-they-aren'

Re: Problem

2009-10-15 Thread Xavier Ho
On Fri, Oct 16, 2009 at 3:28 AM, Ander wrote: > I can't send emails out. Can u fix this problem please? > I don't know what I'm missing here, but you evidently sent out an email to the Python mailing list... Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: md5 strange error

2009-10-21 Thread Xavier Ho
On Wed, Oct 21, 2009 at 6:11 PM, catalinf...@gmail.com < catalinf...@gmail.com> wrote: > >>> pass = md5.new() > File "", line 1 >pass = md5.new() > ^ > SyntaxError: invalid syntax > pass is a keyword in Python, you can't use it as an identifier. Try password instead. Cheers, Xav --

Re: Feedback wanted on programming introduction (Python in Windows)

2009-10-30 Thread Xavier Ho
Alf, I kindly urge you to re-read bartc's comments. He does have a good point and you seem to be avoiding direct answers. On Fri, Oct 30, 2009 at 1:17 PM, Alf P. Steinbach wrote: > * bartc: > >> You say elsewhere that you're not specifically teaching Python, but the >> text is full of technical

Re: Feedback wanted on programming introduction (Python in Windows)

2009-10-30 Thread Xavier Ho
On Fri, Oct 30, 2009 at 1:48 PM, Alf P. Steinbach wrote: > Does that mean that 'print' is still subject to change as of 3.1.1? Funny that. They removed reduce() when Python moved from 2.6.x to 3.0. They even removed __cmp__(). Makes me a sad panda. Is print() subject to change as of 3.1.1? I'd

Re: Help resolve a syntax error on 'as' keyword (python 2.5)

2009-11-03 Thread Xavier Ho
I don't have Python 25 on my computer, but since codepad.org is using Python 2.5.1, I did a quick test: # input try: raise Exception("Mrraa!") except Exception as msg: print msg # output t.py:3: Warning: 'as' will become a reserved keyword in Python 2.6 Line 3 except Exception as ms

Re: Program to compute and print 1000th prime number

2009-11-07 Thread Xavier Ho
On Sun, Nov 8, 2009 at 12:44 AM, Ray Holt wrote: > I have a assignment to write a program to compute and print the 1000th. > prime number. Can someone give me some leads on the correct code? > Ray, if you really want an answer out of this list, you'll have to at least show us what efforts you'v

Re: Logic operators with "in" statement

2009-11-16 Thread Xavier Ho
On Tue, Nov 17, 2009 at 12:02 AM, Mr.SpOOn wrote: > Hi, > I'm trying to use logical operators (or, and) with the "in" statement, > but I'm having some problems to understand their behavior. > Hey Carlo, I think your issue here is mistaking 'in' as a statement. It's just another logic operator, m

Re: Logic operators with "in" statement

2009-11-16 Thread Xavier Ho
On Tue, Nov 17, 2009 at 12:08 AM, Mr.SpOOn wrote: > Sorry for replying to myself, but I think I understood why I was wrong. > > The correct statement should be something like this: > > In [13]: ('b3' and '5') in l or ('3' and 'b3') in l > Out[13]: True > > Carlo, I'm not sure what that achieves.

Re: Logic operators with "in" statement

2009-11-16 Thread Xavier Ho
On Tue, Nov 17, 2009 at 12:46 AM, Chris Rebert wrote: > On Mon, Nov 16, 2009 at 6:23 AM, Xavier Ho wrote: > > AND operator has a higher precedence, so you don't need any brackets > here, I > > think. But anyway, you have to use it like that. So that's something &g

Re: What is the difference between 'except IOError as e:' and 'except IOError, e:'

2009-11-17 Thread Xavier Ho
On Wed, Nov 18, 2009 at 12:28 PM, Peng Yu wrote: > I don't see any different between the following code in terms of > output. Are they exactly the same ('as' v.s. ',')? > Yes, they're exactly the same. However, the syntax with "as" is newer, introducted in Python 3.x, and eventually backported t

Re: How to get UTC offset for non-standard time zone names?

2010-01-31 Thread Xavier Ho
This may not answer your question directly, but have you thought about ingoring the number at the end of these non-standard timezones? CDT is Central Daylight-saving Timezone, while CST is Central Standard Timezone. And you are correct they are -5 and -6 hours respectively. Does pytz know about CDT

Re: How to get UTC offset for non-standard time zone names?

2010-01-31 Thread Xavier Ho
Would it hurt if you put in some extra information? http://www.timeanddate.com/library/abbreviations/timezones/ HTH, -Xav P.S: You, sir, have an awesome first name. On Mon, Feb 1, 2010 at 1:57 AM, Skip Montanaro wrote: > > Does pytz know about CDT and CST? > > Nope... > > Skip > > > -- > htt

Re: Common area of circles

2010-02-04 Thread Xavier Ho
I'm not sure what you're after. Are you after how to calculate the area? Or are you trying to graph it? Or an analytical solution? What do you mean by "take out the intersection"? -Xav On Thu, Feb 4, 2010 at 9:47 PM, Shashwat Anand wrote: > I wanted some general suggestion/tips only > > > On Th

Re: Common area of circles

2010-02-04 Thread Xavier Ho
It's an interesting problem. Never thought it was this difficult. I can't account for all geometrical enumerations, but assuming all 4 circles intersect, here's the solution for this particular senario. It's probably not going to be useful to you since you're working on geometrical approximations n

Re: Your beloved python features

2010-02-04 Thread Xavier Ho
Personally, I love the fact that I can type in 2**25 in the intepreter without crashing my machine. ;) Cheers, -Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with lambda

2010-02-18 Thread Xavier Ho
I'm looking at your code and was thinking ... why writing code that is difficult to understand? To answer your question though, they're different because in case "f", your lambda experssion is only evaluated once. That means the variable 'n' is ever only created once, and replaced repeatedly. In t

Re: How to make an empty generator?

2010-02-18 Thread Xavier Ho
I don't think it's a stupid question at all. =]. But wouldn't it solve the problem if you call the generator the first time you need it to yield? Cheers, Xav On Fri, Feb 19, 2010 at 9:30 AM, Robert Kern wrote: > On Feb 18, 5:08 pm, Steven D'Aprano > wrote: > > On 2010-02-18 16:25 PM, Stephen

Curiosity stirkes me on 'import this'.

2010-03-07 Thread Xavier Ho
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn. Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr! And some other attributes in 'this' module as well, that decodes the string. I'm curious. Was this encoded purely for fun? *grins* Cheers, C

Re: GC is very expensive: am I doing something wrong?

2010-03-18 Thread Xavier Ho
Weeble, Try to use the full arguments of insert(i, x), instead of using list slices. Every time you create a slice, Python copies the list into a new memory location with the sliced copy. That's probably a big performance impact there if done recursively. My 2cp, Xav On Fri, Mar 19, 2010 at 10:

Re: "Usability, the Soul of Python"

2010-03-30 Thread Xavier Ho
Did no one notice that for(i = 99; i > 0; ++i) Gives you an infinite loop (sort of) because i starts a 99, and increases every loop? Cheers, Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: h

Re: String Formatting Operations for decimals.

2010-04-01 Thread Xavier Ho
Hi Maxim, If it's the trailing zeroes you're concerned about, here's a work-around: >>> ('%.2f' % 10.5678).rstrip('0') '10.57 I'm sure there are better solutions. But this one works for your need, right? Cheers,' Ching-Yun Xavier Ho,

Re: PyGame migrating to JavaScript

2010-04-02 Thread Xavier Ho
Javascript in recent years has been getting better and better, and > now is a way better language than python. So to keep up with the > times pygame has been rewritten for javascript. > *shudders* Can someone convince me why that is a good idea at all? Any rationales? Cheers, -Xav -- http:/

Re: PyGame migrating to JavaScript

2010-04-02 Thread Xavier Ho
On Fri, Apr 2, 2010 at 6:19 PM, Gary Herron wrote: > It's a joke -- see > http://en.wikipedia.org/wiki/April_Fools%27_Da D'oh! Can't believe that got me. (It's already 2nd of April... you're not supposed to make that joke now! =p) Cheers, Xav

Re: pynotify for python 3.1.. Help Please..

2010-04-02 Thread Xavier Ho
Hi Jebamnana, You'll probably have to copy the pynotify contents to the Python 3.1 folder. (under Libs\site-packages). You should be able to find the folder in the Python 2.6 paths. Once you do that, you can try to use it. But I don't know if pynotify will be able to run with Python 3.1. For inst

Re: pynotify for python 3.1.. Help Please..

2010-04-02 Thread Xavier Ho
On Fri, Apr 2, 2010 at 8:13 PM, Xavier Ho wrote: > Hi Jebamnana, > Jebagnana* Sorry. -Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a string

2010-04-02 Thread Xavier Ho
Best I can come up with: >>> def split_number(string): ... output = [string[0]] ... for character in string[1:]: ... if character.isdigit() != output[-1].isdigit(): ... output.append('') ... output[-1] += character ... return tuple(output) ... >>> split_numb

Re: Hey Sci.Math, Musatov here. I know I've posted a lot of weird stuff trying to figure things out, but I really think I am onto something here and need some bright minds to have a look at this, co

2010-04-02 Thread Xavier Ho
On Fri, Apr 2, 2010 at 8:14 PM, A Serious Moment wrote: > SPARSE COMPLETE SETS FOR NP: > SOLUTION OF A CONJECTURE > BY MARTIN MICHAEL MUSATOV * > > for llP: > > Sparse Comp1ete Sets > Solution of a Conjecture > Hi, If you're serious about this posting, could you please: 1) Provide a link to a P

Re: Splitting a string

2010-04-02 Thread Xavier Ho
output[-1]) ... output.append('') ... output[-1] += character ... return tuple(output) ... >>> split_number('si_pos_99_rep_1_0.ita') ('si_pos_', 99, '_rep_', 1, '_', 0, '.ita') Cheers, Xav On Fri, Apr 2, 2010 at 8:26 PM,

Re: Python OGL package

2010-11-16 Thread Xavier Ho
Also try Pyglet, in combination of PyOpenGL. Cheers, Xav On 17 November 2010 04:36, Marc-Andre Belzile < marc-andre.belz...@autodesk.com> wrote: > Hi list, > > > > could someone recommend a good python ogl package (open source is > preferred) ? I found these ones so far: > > > > http://pyopengl

Re: How do I get the email address of the person who clicked the link in the email?

2010-12-04 Thread Xavier Ho
As a suggestion, you can auto-format your email link so that the email of the user is sent as part of the URL GET argument. Cheers, Xav On 5 December 2010 08:15, Zeynel wrote: > Hello, > > I am working with Google App Engine python version. The app sends an > email to the user with a link to a

Re: pythonrag

2010-04-05 Thread Xavier Ho
Python caches objects for reuse, but I'm not too certain on how it works, either. Seems a bit odd. I just tested on 2.6.5 and got the same result. This hasn't been a problem for me, though. Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: sum for sequences?

2010-04-06 Thread Xavier Ho
On Tue, Apr 6, 2010 at 11:39 PM, Albert van der Horst < alb...@spenarnc.xs4all.nl> wrote: > Now for floating point numbers the order of summation is crucial, > not commutative (a+b)+c <> a+(b+c). > Could you shed some light on why is this? Cheers, Xav -- http://mail.python.org/mailman/listinfo

Re: pass object or use self.object?

2010-04-06 Thread Xavier Ho
> So my question is whether it's bad practice to set things up so each > method operates on self.document or should I pass document around from > one function to the next? > I think this depends on the use case. If the functions you're calling in between have a chance to be called independently,

Re: pass object or use self.object?

2010-04-06 Thread Xavier Ho
On Wed, Apr 7, 2010 at 1:19 AM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > Usually, when using classes as namespace, functions are declared as static > (or as classmethod if required). > e.g. > > > class Foo: > @classmethod > def process(cls, document): > print 'process of'

Re: Python does not allow a variable named "pass"

2010-04-11 Thread Xavier Ho
On Sun, Apr 11, 2010 at 11:40 PM, BJ Swope wrote: > Other than asking the website owner to change the name of the field > how can I go about passing that field in the form post? > How about: >>> urllib.urlencode({'pass' : 'foo'}) And so on? What is your problem in this context? Cheers, Xav --

Re: curious about python version numbers

2010-04-13 Thread Xavier Ho
Hi Alex, It's because Python 3.x introduced a lot of backwards incompatibilities. Python 2.7 aims to bridge that gap, so many 3rd party libraries that depend on Python 2.x can transit onto Python 3.x better, as I understand. Cheers, Xav On Mon, Apr 12, 2010 at 12:52 PM, Alex Hall wrote: > Hi

Re: Calling a class method

2010-04-17 Thread Xavier Ho
On Sat, Apr 17, 2010 at 11:09 PM, vsoler wrote: > I have the following script: > > class TTT(object): >def duplica(self): >self.data *= 2 >def __init__(self, data): >self.data = data >TTT.duplica(self.data) > You're calling duplica with the class, and not by its o

Default paranmeter for packed values

2010-04-18 Thread Xavier Ho
uot;", line 1 def t(a, *b = (3, 4)): ^ SyntaxError: invalid syntax What was the rationale behind this design? Cheers, Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -

Re: Default paranmeter for packed values

2010-04-18 Thread Xavier Ho
On Mon, Apr 19, 2010 at 9:46 AM, Chris Rebert wrote: > It doesn't really make sense to use * in such situations anyway, you > can just do the normal `z = (1,2,3)` But calling function(1.0, (0.0, 1.0, 0.0)) has been a big pet peeve of mine, and it looks extremely ugly and, imo, unpythonic. On M

Re: problems creating and adding class instances to a list:

2010-04-19 Thread Xavier Ho
On Tue, Apr 20, 2010 at 7:21 AM, Robert Somerville < rsomervi...@sjgeophysics.com> wrote: > class ctest(): > x = int > y = [1,2,3] > Variables defined directly under the class are known as "static variables" in many other languages. Here in Python it's called a class variable, but they're sti

Re: problems creating and adding class instances to a list:

2010-04-19 Thread Xavier Ho
On Tue, Apr 20, 2010 at 7:38 AM, Chris Rebert wrote: > Additionally, `self.x = int` might not do what you thought it does. It > does *not* create a new instance variable of type 'int'. Instead, it > literally assigns to a new instance variable x the *function*† that > converts values into integer

Re: Re: Code redundancy

2010-04-20 Thread Xavier Ho
On Wed, Apr 21, 2010 at 7:59 AM, Alan Harris-Reid < aharrisr...@googlemail.com> wrote: > The code is not usually in class.__init__ (otherwise I would have used the > self. prefix) Alan, if your variables are not usually in __init__, what's preventing you from using class variables like this: >>

Re: Hi, friends. I wanna ask if there is a function which is able to take a list as argument and then return its top-k maximums?

2010-04-22 Thread Xavier Ho
On Fri, Apr 23, 2010 at 12:04 AM, Tim Golden wrote: > Assuming top-k doesn't mean something obscurely statistical: > > l = [1,2, 3, 4, 5] > k = 3 > print (sorted (l, reverse=True)[:k]) > You don't really need to reverse sort there: >>> numbers = [1, 4, 5, 3, 7, 8] >>> sorted(numbers)[3:] [5, 7,

Re: Hi, friends. I wanna ask if there is a function which is able to take a list as argument and then return its top-k maximums?

2010-04-22 Thread Xavier Ho
On Fri, Apr 23, 2010 at 12:23 AM, D'Arcy J.M. Cain wrote: > Now try returning the top two or four numbers. > >>> numbers = [1, 4, 5, 3, 7, 8] >>> sorted(numbers)[-2:] [7, 8] >>> sorted(numbers)[-4:] [4, 5, 7, 8] I see what you mean. This is not as intuitive, is it? Cheers, Xav -- http://mail

Re: Engineering numerical format PEP discussion

2010-04-25 Thread Xavier Ho
On Mon, Apr 26, 2010 at 3:19 PM, Chris Rebert wrote: > Apparently either you and the General Decimal Arithmetic spec differ > on what constitutes engineering notation, there's a bug in the Python > decimal library, or you're hitting some obscure part of the spec's > definition. I don't have the e

Re: Engineering numerical format PEP discussion

2010-04-25 Thread Xavier Ho
On Mon, Apr 26, 2010 at 3:39 PM, Chris Rebert wrote: > "The conversion **exactly follows the rules for conversion to > scientific numeric string** except in the case of finite numbers > **where exponential notation is used.**" > Well, then maybe the conversion doesn't exactly follow the rules, i

Re: How to check what is holding reference to object

2010-04-27 Thread Xavier Ho
Michal, May I ask why do you care about the object's management? Let Python worry about that. What's your use case? -- http://mail.python.org/mailman/listinfo/python-list

Re: dynamic function add to an instance of a class

2010-04-29 Thread Xavier Ho
On Thu, Apr 29, 2010 at 5:55 PM, Richard Lamboj wrote: > > Hello, > > i want to add functions to an instance of a class at runtime. The added > function should contain a default parameter value. The function name and > function default paramter values should be set dynamical. > > Kind Regards, > >

Re: column selection

2010-05-06 Thread Xavier Ho
You need to ignore empty lines. for line in open('1.txt'): if len(line.strip()) == 0: continue columns = line.split() print columns[0], columns[2] Cheers, Xav On Thu, May 6, 2010 at 6:22 PM, mannu jha wrote: > Hi, > > I have few files like this: > > 24 ALA helix (helix_alph

Re: [Python-ideas] division oddness

2010-05-06 Thread Xavier Ho
On Fri, May 7, 2010 at 11:13 AM, Chris Rebert wrote: > On Thu, May 6, 2010 at 5:43 PM, Mathias Panzenböck > wrote: > > Shouldn't by mathematical definition -x // y be the same as -(x // y)? > > I think this rather odd. Is there any deeper reason to this behaviour? I > > guess changing this will

Re: [Python-ideas] division oddness

2010-05-06 Thread Xavier Ho
On Fri, May 7, 2010 at 12:14 PM, Chris Rebert wrote: > Personally, I find the following the most unintuitive: > divmod(-11, 3) == (-4, 1) > > So, we overshoot -11 and then add 1 to go back to the right place? > That violates my intuitive thought that abs((n//d)*d) <= abs(n) ought to > hold. > Ha

Re: Why list comprehension faster than for loop?

2010-05-09 Thread Xavier Ho
On Sun, May 9, 2010 at 6:20 PM, gopi krishna wrote: > Why list comprehension faster than for loop? > > Because Python optimises for certain special cases, when the number of iterations is predicable in a list comprehension. Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: can we change the variables with function

2010-05-09 Thread Xavier Ho
On Sun, May 9, 2010 at 6:19 PM, gopi krishna wrote: > Hi >can I change the variable in a function using the function > suppose > >>>def a(): > x=20 > can we change the variable using the function > Can you give us an example of how you'd like to "change the variable", in code, and show us wha

Re: solve a newspaper quiz

2010-05-09 Thread Xavier Ho
On Sun, May 9, 2010 at 7:20 PM, superpollo wrote: > "if a b c are digits, solve ab:c=a*c+b" > Sorry, what does the notation ab:c mean? Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Extract all words that begin with x

2010-05-10 Thread Xavier Ho
Have I missed something, or wouldn't this work just as well: >>> list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas'] >>> [word for word in list_of_strings if word[0] == 'a'] ['awes', 'asdgas'] Cheers, Xav On Mon, May 10, 2010 at 6:40 PM, Jimbo wrote: > Hello > > I am trying to find

Re: help need to write a python spell checker

2010-05-15 Thread Xavier Ho
1) Welcome to Python-List! 2) Python-list doesn't like to do other people's homework. 3) What have you tried? Cheers, Xav On Fri, May 14, 2010 at 6:19 PM, harry k wrote: > Write a spell checking tool that will identify all misspelled word in a > text file using a provided dictionary. > > > Th

Re: Human word reader

2010-05-15 Thread Xavier Ho
On Sat, May 15, 2010 at 9:02 PM, timo verbeek wrote: > I'm planning to create a human word program > > > I need help with getting the useful information how do I get the place > if I don't now how long the string is? > > Boy, that is a very hard problem. Are the inputs restricted to anything? E

Re: Human word reader

2010-05-15 Thread Xavier Ho
On Sat, May 15, 2010 at 9:12 PM, Xavier Ho wrote: > You need to have a very, very good set of heruistics and deterministic > functions to do that. > > "How do I get the position of a known word in a string if the length if > unknown?" > And this is what I get f

Re: Human word reader

2010-05-15 Thread Xavier Ho
On Sat, May 15, 2010 at 9:32 PM, timo verbeek wrote: > On May 15, 1:02 pm, timo verbeek wrote: > Place starts always with for > Okay, much better. Given that constraint, it looks like regular expression can do the job. I'm not very experienced with regex, though. \w* matches a whole word compo

Re: help need to write a python spell checker

2010-05-18 Thread Xavier Ho
Yeah, most unis here commence in March, and the first semester usually finish in June, when the exams are. - Xav on his 'droid On 19/05/2010 2:21 PM, "Patrick Maupin" wrote: On May 14, 3:19 am, "harry k" wrote: > Write a spell checking tool that wil... Well, this has been educational. Both m

Re: __str__ for each function in a class

2010-05-19 Thread Xavier Ho
On 5/19/2010 1:14 AM, Vincent Davis wrote: > class C(object): >> def __init__(self, new): >> self.letter = dict(a=1,b=2,c=3, amin=np.amin) >> self.new = new >> self._x = None >> self._Y = None >> >> @property >> def x(self): >> """I'm the 'x' property.""

Re: where are the program that are written in python?

2010-05-21 Thread Xavier Ho
On Fri, May 21, 2010 at 9:12 PM, Deep_Feelings wrote: > thankx for reply. > > from that list i have a feeling that python is acting only as "quick > and dirty work" nothing more ! > You might have just offended a lot of people on the list here Cheers, Xav -- http://mail.python.org/mailman

Re: where are the program that are written in python?

2010-05-22 Thread Xavier Ho
On Sun, May 23, 2010 at 3:35 PM, sturlamolden wrote: > Yes I know about PyOpenGL, but then there is the speed argument: From > C I can make epeated calls to functions like glVertex4f with minial > loss of efficacy. Calling glVertex4f from Python (e.g. PyOpenGL) would > give me the Python (and pos

Re: if, continuation and indentation

2010-05-27 Thread Xavier Ho
On 27 May 2010 22:22, HH wrote: >if (width == 0 and >height == 0 and >color == 'red' and >emphasis == 'strong' or >highlight > 100): >raise ValueError("sorry, you lose") > I've gotta say - I've bumped into this problem before, and I'm sure many other h

Re: if, continuation and indentation

2010-05-27 Thread Xavier Ho
On 27 May 2010 22:57, Jean-Michel Pichavant wrote: > One possible solution > > if ( > width == 0 and > height == 0 and > color == 'red' and > emphasis == 'strong' or > highlight > 100 > ): > raise ValueError("sorry, you lose") > > But

Re: if, continuation and indentation

2010-05-27 Thread Xavier Ho
On 27 May 2010 22:57, Jean-Michel Pichavant wrote: > One possible solution >> >> if ( >> width == 0 and >> height == 0 and >> color == 'red' and >> emphasis == 'strong' or >> highlight > 100 >> ): >> raise ValueError("sorry, you lose

Re: if, continuation and indentation

2010-05-27 Thread Xavier Ho
On 27 May 2010 23:26, Xavier Ho wrote: > Oh, one minor optimisation. You can put the last condition first > I take that back. You really can't, without using more parans or ifs. Apologies. -Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: A Friday Python Programming Pearl: random sampling

2010-05-29 Thread Xavier Ho
On 29 May 2010 06:44, Mark Dickinson wrote: > But I was struck by its beauty and > simplicity, and thought it deserved to be better known. > Wow, that took me at least 2 minutes to see its beauty as well. Nice find, Mark. Thanks for sharing. (Also, it's nice to see another SOer on Python-List a

Re: Creating a single list

2010-05-29 Thread Xavier Ho
On 29 May 2010 23:24, Astley Le Jasper wrote: > def createlist(): >column_title_list = ( >("id",20,"integer"), >("companyname",50,"text"), >getproducts(), >

Re: Creating a single list

2010-05-29 Thread Xavier Ho
> # Insert into the list with slicing syntax. >column_title_list[2:3} = getproduct() > Sorry, that should have been [2:3]. Typing a bit too fast. -Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: reading help() - newbie question

2010-05-31 Thread Xavier Ho
On 31 May 2010 20:19, Payal wrote: > Hi, > I am trying to learn Python (again) and have some basic doubts which I > hope someone in the list can address. (English is not my first language and > I > have no CS background except I can write decent shell scripts) > > Welcome (back) to the Python-Lis

Re: Question about permutations (itertools)

2010-05-31 Thread Xavier Ho
> >>> list(combinations_with_replacement('01',3)) > ('0', '0', '0') > ('0', '0', '1') > ('0', '1', '1') > ('1', '1', '1') > > Is it possible to get combinations_with_replacement to return numbers > rather than strings? (see above) > >>> list(combinations_with_replacement(range(0,2), 3)) [(0, 0, 0)

Re: What does this PyChecker warning mean?

2010-06-01 Thread Xavier Ho
On 1 June 2010 21:48, Leo Breebaart wrote: > > When fed the following code: > > def Foo(): > >class A(object): >def __init__(self): >pass > >class B(object): >def __init__(self): >pass > > PyChecker 0.8.18 warns: > > foo.py:9: Redefining attribute

Re: a +b ?

2010-06-11 Thread Xavier Ho
2010/6/12 yanhua > hi,all! > it's a simple question: > input two integers A and B in a line,output A+B? > > this is my program: > s = input() > t = s.split() > a = int(t[0]) > b = int(t[1]) > print(a+b) > > but i think it's too complex,can anybody tell to slove it with less code. > -- > The reas

Re: pythonize this!

2010-06-15 Thread Xavier Ho
On 15 June 2010 21:49, superpollo wrote: > goal (from e.c.m.): evaluate > 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three > consecutive + must be followed by two - (^ meaning ** in this context) > Obligatory one-liner: >>> sum((1, 1, 1, -1, -1)[(x-1) % 5] * x**2 for x in x

Re: pythonize this!

2010-06-15 Thread Xavier Ho
On 15 June 2010 22:55, superpollo wrote: > Peter Otten ha scritto: > > superpollo wrote: >> >> goal (from e.c.m.): evaluate >>> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three >>> consecutive + must be followed by two - (^ meaning ** in this context) >>> >> >> from iterto

  1   2   3   >