Re: Checking homogeneity of Array using List in Python

2013-08-24 Thread Chris Angelico
On Sun, Aug 25, 2013 at 3:50 PM, wrote: > NOTE: NO INBUILT FUNCTION BE USED. Thank you in advance. You'll have to do your own homework, then. Python strongly favours the use of inbuilt functions. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Checking homogeneity of Array using List in Python

2013-08-24 Thread sahil301290
I am unable to check homogeneity of Array. I have take Array type Int to be default for my code. Instead of getting Error on NON-INT Values. I want to take input as string. Then check if all input is in (0-9) form, I typecast it into int and Accept. Else, I would like to skip that input. eg. my i

Re: List getting extended when assigned to itself

2013-08-24 Thread Steven D'Aprano
On Sun, 25 Aug 2013 09:22:27 +0530, Krishnan Shankar wrote: > Hi Python Friends, > > I came across an example which is as below, > var = [1, 12, 123, 1234] var > [1, 12, 123, 1234] var[:0] > [] var[:0] = var var > [1, 12, 123, 1234, 1, 12, 123, 1234] > Here in

Re: New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread Michael Torrie
On 08/24/2013 10:06 PM, Benjamin Kaplan wrote: > On Sat, Aug 24, 2013 at 7:08 PM, Michael Torrie wrote: >> #Linux, #Python? This this hash tag stuff is getting out of hand, don't >> you think? > > Didn't you hear? In an effort to redefine itself for the modern > Internet, Usenet is adding suppor

Re: New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 7:08 PM, Michael Torrie wrote: > #Linux, #Python? This this hash tag stuff is getting out of hand, don't > you think? Didn't you hear? In an effort to redefine itself for the modern Internet, Usenet is adding support for hash tags and limiting posts to 140 characters beca

Re: List getting extended when assigned to itself

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 8:52 PM, Krishnan Shankar wrote: > Hi Python Friends, > > I came across an example which is as below, > var = [1, 12, 123, 1234] var > [1, 12, 123, 1234] var[:0] > [] var[:0] = var var > [1, 12, 123, 1234, 1, 12, 123, 1234] > > Here in var[:0]

List getting extended when assigned to itself

2013-08-24 Thread Krishnan Shankar
Hi Python Friends, I came across an example which is as below, >>> var = [1, 12, 123, 1234] >>> var [1, 12, 123, 1234] >>> var[:0] [] >>> var[:0] = var >>> var [1, 12, 123, 1234, 1, 12, 123, 1234] >>> Here in var[:0] = var we are assigning an entire list to the beginning of itself. So shouldn't

Re: New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread Michael Torrie
#Linux, #Python? This this hash tag stuff is getting out of hand, don't you think? -- http://mail.python.org/mailman/listinfo/python-list

Re: Setting the value of True

2013-08-24 Thread Gregory Ewing
Steven D'Aprano wrote: As for why None, True and False are treated differently than built-ins, if I remember the reason why, it is because they are considered fundamental to the inner workings of Python, unlike mere builtins like len, map, etc. and therefore should be protected. It's probably

Re: Lambda function Turing completeness

2013-08-24 Thread Piet van Oostrum
This is the second part of my posting on the Turing completeness of Python's lambda expressions. This time I am going to define a recursive function as a lambda expression (I use lambda when I am talking about Python's lambda expressions, and λ for the theory – λ calculus.) Now of course it is eas

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread random832
On Sat, Aug 24, 2013, at 12:47, David M. Cotter wrote: > > What _are_ you using? > i have scripts in a file, that i am invoking into my embedded python > within a C++ program. there is no terminal involved. the "print" > statement has been redirected (via sys.stdout) to my custom print class, >

Re: Lambda function Turing completeness

2013-08-24 Thread Piet van Oostrum
Musical Notation writes: > Is it possible to write a Turing-complete lambda function (which does > not depend on named functions) in Python? The wording of this question is questionable. Turing completeness is not an attribute of a function, but of a system (for example a programming language or

Re: Exception Handling Practices / Patterns

2013-08-24 Thread frank . ruiz
Hi Steven, Yea this is great. Thanks for the feedback. On Saturday, August 24, 2013 3:27:45 AM UTC-7, Steven D'Aprano wrote: > On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote: > > > > [...] > > > * Seems like exception handing within Classes is largely avoided and is > > > typically only use

Re: Exception Handling Practices / Patterns

2013-08-24 Thread frank . ruiz
Appreciate the feedback. I was hoping to get as much perspective as possible. On Saturday, August 24, 2013 12:18:59 AM UTC-7, Dave Angel wrote: > snarf wrote: > > > > > Greetings, > > > > > > As I tread through my journey of OO I am trying to determine if there is a > > good approach for ex

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Steven D'Aprano
On Sat, 24 Aug 2013 15:57:55 -0400, Terry Reedy wrote: >> # Worst >> except: >> >> Don't use the last one, except maybe in the interactive interpreter, > > Stick with never. "except:" means the same thing as "except > BaseException:", except that the latter indicates a deliberate choice > rather

Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Tim Delaney
On 25 August 2013 07:59, Tim Delaney wrote: > Breakdown of the above (for 19 digits): > > d.as_tuple() takes about 35% of the time. > > The multiply and add takes about 55% of the time. > > The exponentiation takes about 10% of the time. > Bah - sent before complete. Since the multiply and add

Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Tim Delaney
On 24 August 2013 13:30, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > > def convert(d): > sign, digits, exp = d.as_tuple() > num = int(''.join([str(digit) for digit in digits])) > if sign: num = -num > return num, 10**-exp > > which is faster, but not fast enoug

New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread vasudevram
This may be of interest to readers of this newsgroup: Original article: http://lnkd.in/taAFNt Content (without links): A new way of writing socket servers has been introduced with the Linux kernel 3.9. It involves the ability to bind multiple listening sockets to the same port on the same

Help in Nltk

2013-08-24 Thread projectfack
Can anyone help me for the tasks below in nltk 1. The system mustdemonstrate false positiveand false negativeexamples using any stemmer (Task 1.1) 2. The system mustdemonstrate the differences between successive layers of

Re: Using PyQT with QT Designer

2013-08-24 Thread tausciam
Thanks. I probably will do exactly like you suggested later on. But, those two lines have solved the problem I had and I can work on the actual program now. I can come back to the GUI later. Here is what it looks like now: http://i.imgur.com/sLiSU6M.png On Friday, August 23, 2013 7:35:53 PM UTC

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Terry Reedy
On 8/24/2013 6:27 AM, Steven D'Aprano wrote: On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote: [...] * Seems like exception handing within Classes is largely avoided and is typically only used when calling external libraries. There is certainly no rule "avoid exceptions inside classes". Method

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 9:47 AM, David M. Cotter wrote: > > > What _are_ you using? > i have scripts in a file, that i am invoking into my embedded python within a > C++ program. there is no terminal involved. the "print" statement has been > redirected (via sys.stdout) to my custom print clas

Re: python interface to iMacros

2013-08-24 Thread inq1ltd
> On 08/23/2013 09:13 AM, inq1ltd wrote: > > Python help, > > > > I am running iMacros from > > linux/firefox and doing most of > > what I want. > > > > But, there are times when I want to > > do something of the net and then > > back to the iMacros script. > > > > Are there any projects out th

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread wxjmfauth
Le samedi 24 août 2013 18:47:19 UTC+2, David M. Cotter a écrit : > > What _are_ you using? > > i have scripts in a file, that i am invoking into my embedded python within a > C++ program. there is no terminal involved. the "print" statement has been > redirected (via sys.stdout) to my custom

how to read mixed from multiple csv file

2013-08-24 Thread Jia Hu
Hi, My 20 csv files has string header, and first two columns are string (e.g., 1999-01-02, 01:00:00) among the 50 columns. Other columns store numerical values (int, or float) I need to do data analysis for these data. For example, extract the each month data from each of the cvs files (each c

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread David M. Cotter
> What _are_ you using? i have scripts in a file, that i am invoking into my embedded python within a C++ program. there is no terminal involved. the "print" statement has been redirected (via sys.stdout) to my custom print class, which does not specify "encoding", so i tried the suggestion a

Re: Exception Handling Practices / Patterns

2013-08-24 Thread MRAB
On 24/08/2013 11:27, Steven D'Aprano wrote: On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote: [snip] * Using Exception is typically a bad. More specific the better. Yes, you should always try to catch the specific exceptions you care about: # Best except ValueError, OverflowError, ZeroDivisi

Re: python interface to iMacros

2013-08-24 Thread Michael Torrie
On 08/23/2013 09:13 AM, inq1ltd wrote: > Python help, > > I am running iMacros from linux/firefox > and doing most of what I want. > > But, there are times when I want to do > something of the net and then back > to the iMacros script. > > Are there any projects out there > that will conne

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread random832
On Sat, Aug 24, 2013, at 2:45, David M. Cotter wrote: > > you need to use u" ... " delimiters for Unicode, otherwise the results you > > get are completely arbitrary and depend on the encoding of your terminal. > okay, well, i'm on a mac, and not using "terminal" at all. but if i > were, it woul

Re: Help regarding urllib

2013-08-24 Thread Dave Angel
malhar vora wrote: > On Saturday, August 24, 2013 4:15:01 PM UTC+5:30, malhar vora wrote: >> Hello All, >> >> >> >> >> >> I am simply fetching data from robots.txt of a url. Below is my code. >> >> >> >> siteurl = siteurl.rstrip("/") > > Sorry for last complete. It was sent by mistake. > >

Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Peter Otten
Steven D'Aprano wrote: > I have a need to convert arbitrary non-complex numbers into numerator/ > denominator pairs. Numbers could be ints, floats, Fractions or Decimals. > For example: > > 2 => (2, 1) > 0.25 => (1, 4) > Fraction(2, 3) => (2, 3) > Decimal("0.5") => (1, 2) > > > The first three

Re: How to send broadcast IP address to network?

2013-08-24 Thread Irmen de Jong
On 23-8-2013 14:32, lightai...@gmail.com wrote: > I want to send a broadcast packet to all the computers connected to my home > router. > > The following 2 lines of code do not work; > host="192.168.0.102" > s.connect((host, port)) > > Can someone advise? > > Thank you. > Use UDP (datagram)

Re: Python variable as a string

2013-08-24 Thread Jake Angulo
Thank you all for the reply. Actually yes this was a confusing question, and borne out of trying to make a shortcut. I didnt ask to convert the contents of var into a string. All I needed was to get the literal equivalent "var" because I needed to use it in another dict object - whose keys i named

Re: Help regarding urllib

2013-08-24 Thread malhar vora
On Saturday, August 24, 2013 4:15:01 PM UTC+5:30, malhar vora wrote: > Hello All, > > > > > > I am simply fetching data from robots.txt of a url. Below is my code. > > > > siteurl = siteurl.rstrip("/") Sorry for last complete. It was sent by mistake. Here is my code. siteurl = siteurl.rs

Help regarding urllib

2013-08-24 Thread malhar vora
Hello All, I am simply fetching data from robots.txt of a url. Below is my code. siteurl = siteurl.rstrip("/") -- http://mail.python.org/mailman/listinfo/python-list

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Steven D'Aprano
On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote: [...] > * Seems like exception handing within Classes is largely avoided and is > typically only used when calling external libraries. There is certainly no rule "avoid exceptions inside classes". Methods often raise exceptions to signal an error

Re: Running a command line program and reading the result as it runs

2013-08-24 Thread Ian Simcock
Peter Otten wrote: Ian Simcock wrote: Greetings all. I'm using Python 2.7 under Windows and am trying to run a command line program and process the programs output as it is running. A number of web searches have indicated that the following code would work. import subprocess p = subprocess.P

Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Ian Kelly
On Sat, Aug 24, 2013 at 1:37 AM, Ian Kelly wrote: > > I time this function at about 33% faster than your version for a > six-digit decimal, and almost 50% faster for a 12-digit decimal. My > guess would be because it's not calling str() on every individual > digit. > > def convert(d): > exp =

Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Ian Kelly
On Fri, Aug 23, 2013 at 9:30 PM, Steven D'Aprano wrote: > Is there a fast way to convert a Decimal into a pair of numbers numerator/ > denominator? It *must* be exact, but it doesn't have to be simplest form. > For example, Decimal("0.5") => (5, 10) would be okay, although (1, 2) > would be prefer

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Dave Angel
snarf wrote: > Greetings, > > As I tread through my journey of OO I am trying to determine if there is a > good approach for exception handling within classes. > > From my readings and gatherings - it seems I have found a common theme, but I > am trying to solicit from the experts. > > Here is w

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread Dave Angel
David M. Cotter wrote: > Steven wrote: >> I see you are using Python 2 > correct > >>It's hard to say what *exactly* is happening here, because you don't explain >>how the python print statement somehow gets into your C++ Log code. Do I >>guess right that it catches stdout? > yes, i'm redirecting