Re: the meaning of rユ.......�¾

2012-07-24 Thread Larry Hudson

On 07/23/2012 06:22 AM, Dave Angel wrote:

On 07/23/2012 09:06 AM, Chris Angelico wrote:

On Mon, Jul 23, 2012 at 10:55 PM, Roy Smith  wrote:

Some day, we're going to have programming languages that take advantage
of the full unicode character set.  Right now, we're working in ASCII
and creating silly digrams/trigrams like r'' for raw strings (and triple-quotes 
for multi-line
strings).  Not to mention <=, >=, ==, !=.  And in languages other than
python, things like ->, => (arrows for structure membership), and so on.

REXX predates Unicode, I think, or at least its widespread adoption,
but it has a non-ASCII operator:

http://www.rexswain.com/rexx.html#operators

But personally, I've always used backslash. It's nothing to do with
ASCII and everything to do with having it on the keyboard. Before you
get a language that uses full Unicode, you'll need to have fairly
generally available keyboards that have those keys.

ChrisA



Keyboards with 110,000 keys on them; wonderful.  And much larger
characters on the screen, so that all those can be distinguished.  And
of course all fonts have to support all those characters.

Back to 20 character lines.



Somewhat different than this discussion, and I'm not familiar with it myself, but I've read 
about the "Space Cadet Keyboard".  It's described (among other places) at:


http://catb.org/jargon/html/S/space-cadet-keyboard.html

 -=- Larry -=-

OT:  This "Jargon File" can be an entertaining read.  I found "The Story of Mel" particularly 
fascinating.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Gender, Representativeness and Reputation in StackOverflow

2012-07-24 Thread Alexander Serebrenik
As a scientist I would be more than happy to publish in Open-Access Journals 
rather than in IEEE/ACM/Springer-published ones. However, I also have to be 
sure that my publications reach the scientific community and make an impact on 
it. Unfortunately, in many fields AFAIK the better journals (= higher impact, 
etc) are access-restricted, while the open-access ones are overloaded by 
low-quality submissions and are no much better than a trash bin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-24 Thread Devin Jeanpierre
On Tue, Jul 24, 2012 at 2:23 AM, Mark Lawrence  wrote:
> strictly speaking Python doesn't have variables, it has names.  This will
> possibly start a flame war which, by the standards of this ng/ml, will be an
> intense conflagration, hence the duck and cover.

The two terms are nearly synonymous when one talks about Python (and
both are used in the language reference).

I mean, what's so "strict" about the way you're speaking?

-- Devin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python package confusion

2012-07-24 Thread Devin Jeanpierre
On Tue, Jul 24, 2012 at 1:38 AM, Steven D'Aprano
 wrote:
> I don't know about a bad idea or not, but it is certainly redundant,
> because Python automatically adds '' (equivalent to '.') to the very
> start of the search path.

No, it only does that if Python is reading commands from stdin, or if
Python was run with the -c option, or maybe some other situations. It
doesn't do it if you just run a program, as in "python myfile.py".

-- Devin
-- 
http://mail.python.org/mailman/listinfo/python-list


DjangoCon US 2012

2012-07-24 Thread Steve Holden
Pythonistas:

We are happy to remind all Django users that DjangoCon US is in DC this year, 
from September 3-8 (main conference September 4-6). Early bird pricing is 
available until August 3, and the schedule will be published shortly after this 
announcement is made.

  http://djangocon.us/

Since this is DjangoCon's first ever visit to the East coast we are hoping for 
good attendance from up and down the East coast, but some delegates will come 
from as far away as Australia, so Americans have no excuse!

regards
 Steve
-- 
The Open Bastion is the Holden Web   http://TheOpenBastion.com/
subsidiary responsible forhttp://holdenweb.com/
technical events such as DjangoCon http://djangocon.us/
-- 
http://mail.python.org/mailman/listinfo/python-list


groveling over a file for Q:: and A:: stmts

2012-07-24 Thread paul618
#!/usr/bin/env python
# grep_for_QA.py  I am only looking to isolate uniq Q:: and A:: stmts from my 
daily files
#
# note:  This algorithm will fail if there are any blank lines within the Q and 
A area of interest (a paragraph)

# D. Beazley is my fav documentation

import re, glob
import pprint as pp

sampledata = '''
A:: And Straight Street is playin on the Radio Free Tibet.  What are the 
chances, DTMB?  
Q:: About 1 in 518400, Professor.
A:: Correct!  Err, I thought it was 1:410400, but close enough for jazz!


'''

pattern0 = re.compile("Q::")
pattern1 = re.compile("A::")  # objects of interest can start with A:: ;; not 
alway Q::
END_OF_PARAGRAPH_pat = "\n\s*\n"

path = "/Users/paultaney/dailies2012/0722" # an example of real data set.

toggle = False
L = []
M = []

#file = open(path, "r")
try: 
#for line in file.readlines():
for line in sampledata:  
try:
# Later, I also need to treat Unicode -- and I am clueless.
  
# falsestarts::
#line.encode("utf8").decode('xxx', 'ignore')
#line.encode("utf8", 'ignore') 
#line.decode('8859')  
#line.decode('8859')  # 8859, Latin-1 doesn't cover my  CJK 
pastings  AT ALL
#line.decode('GB18030')  # 171006 -- ack
#encoded_line = line  # xxx line.encode("utf8") 

mo0 = re.search(pattern0, line)
mo1 = re.search(pattern1, line)
mo2 = re.search(END_OF_PARAGRAPH_pat, line)

if mo0:
if 1: print ("I see pattern 0")
toggle = True
if 1: print(line)
M.append(mo0.group())

if mo1:
if 1: print ("I see pattern 1")
toggle = True
M.append(mo1.group())

if mo2 and toggle:
if 1: print ("I see pattern 2 AND toggle is set")
# got one.  save it for uniqifying, and empty the container  
toggle = False
L.append(M)
M = []

except Exception as e:
print("--- " + e + " ---")

except UnicodeDecodeError:
#encoded_line = encoded_line.urlsafe_b64encode(re.replace("asdf", 
encoded_line))
#line = re.sub(".+", "--- asdf ---", line)
pass

L.sort
print (L)

# and what"s wrong with some of this, here!
#myHash = set(L)# uniqify
#pp.pprint(myHash)  # july 23, 131001 hike!
-- 
http://mail.python.org/mailman/listinfo/python-list


How to deal with python 32bit memory error

2012-07-24 Thread Sammy Danso
Hello Experts,
I am having a 'memory error', which suggest that I 
have run out of memory, but I am not sure this is the case as I have 
considerable amount of memory unused on my computer. 

A little 
search suggest this is a limitation of python 32 and an option is to 
have a 64bit. I however have other plug-ins, which are tied to the 32bit
 so this is not the best option in my case. 

I was wondering whether there is an elegant way to dealing with this without 
installing a 6bit version of python.

Thanks very much in advance.
Sammy-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-24 Thread Ulrich Eckhardt
There is one model that has helped me much understanding how Python 
ticks and that is the model of name tags. The code "a = 1" creates an 
integer with value 1 and attaches a tag with "a" written on it using a 
small piece of rope. Now, if you attach the tag to a different item, it 
obviously doesn't change the original integer. Also, you can attach more 
than one tag to the integer or even none. Further, a tag doesn't even 
have to be attached to anything (this happens if you use a local 
variable before assigning to it). This operation of tagging something is 
done with the "=" operator.


Now, coming back to your code...

Am 23.07.2012 16:50, schrieb Stone Li:

I'm totally confused by this code:

Code:


a = None
b = None
c = None
d = None


This adds the tags "a", "b", "c" and "d" to None.



x = [[a,b],
  [c,d]]


"[a, b]" creates a list, containing two anonymous tags (they don't have 
anything written on them but they are accessible via index) attached to 
what "a" and "b" are currently attached to [0]. The same happens for 
"[c, d]". The two lists are then put into another list with a similar 
mechanism, and that list of lists is then tagged "x".




e,f = x[1]


This takes the second element of "x" (the [c, d] above) and tags it with 
"e" and "f". This syntax implicitly unpacks the list so the assignment 
operator adds the two tags "e" and "f" to the first and second element 
referenced by that list. Both "e" and "f" finally end up attached to "None".




c = 1
d = 2


These two remove the rope attaching "c" and "d" to "None" and instead 
attach them to the integers "1" and "2".



I hope your Python's behaviour makes sense to you now!

Uli


[0] Note that in almost all cases, when referring to a tag, Python 
implicitly operates on the object attached to it. One case (the only 
one?) where it doesn't is the "del" statement.

--
http://mail.python.org/mailman/listinfo/python-list


Re: groveling over a file for Q:: and A:: stmts

2012-07-24 Thread Steven D'Aprano
On Tue, 24 Jul 2012 00:50:22 -0700, paul618 wrote:

> #!/usr/bin/env python
> # grep_for_QA.py  I am only looking to isolate uniq Q:: and A:: stmts
> from my daily files #
> # note:  This algorithm will fail if there are any blank lines within
> the Q and A area of interest (a paragraph)
> 
> # D. Beazley is my fav documentation


If you are going to ask a question, please ask a question. Don't just 
dump a whole pile of code in our laps and expect us to work out what your 
question is.

It may help if you read this page:

http://sscce.org/

Some further comments below:

> import re, glob
> import pprint as pp
> 
> sampledata = '''
> A:: And Straight Street is playin on the Radio Free Tibet.  What are the
> chances, DTMB? Q:: About 1 in 518400, Professor.
> A:: Correct!  Err, I thought it was 1:410400, but close enough for
> jazz!
> 
> 
> '''
> 
> pattern0 = re.compile("Q::")

There is no point in using a regular expression for something as trivial 
as that. That is like swinging a 20 kg sledge-hammer to crack a peanut.

Just use a string method:

if my_string.startswith("Q::"): ...


[...]
> # Later, I also need to treat Unicode -- and I am clueless.

If you have a question about Unicode, you should ask it.

If you have not already read this page, you should read it now:

http://www.joelonsoftware.com/printerFriendly/articles/Unicode.html



> except Exception as e:
> print("--- " + e + " ---")

Please don't throw away useful debugging information.

You should learn to read exception tracebacks, not hide them. They 
contain a lot of very useful information to help you debug your code.

> except UnicodeDecodeError:
> #encoded_line = encoded_line.urlsafe_b64encode(re.replace("asdf",
> encoded_line)) #line = re.sub(".+", "--- asdf ---", line) pass

This will never be caught because any UnicodeDecodeError will already be 
caught by the "except Exception" line above.


> L.sort
> print (L)
> 
> # and what"s wrong with some of this, here! #myHash = set(L)#
> uniqify
> #pp.pprint(myHash)  # july 23, 131001 hike!

I don't know what's wrong with it. What do you expect it to do, and what 
does it actually do instead?



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-24 Thread Chris Angelico
On Tue, Jul 24, 2012 at 5:47 PM, Ulrich Eckhardt
 wrote:
> There is one model that has helped me much understanding how Python ticks
> and that is the model of name tags. The code "a = 1" creates an integer with
> value 1 and attaches a tag with "a" written on it using a small piece of
> rope.

A double strand of rope, I think. If it were one strand, we'd write "a - 1". :)

> [0] Note that in almost all cases, when referring to a tag, Python
> implicitly operates on the object attached to it. One case (the only one?)
> where it doesn't is the "del" statement.

I'd say that del is more closely related to assignment than anything
else. You can go "a = None" to mark that a now points to nothing, or
you can "del a" to de-rope a altogether.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-24 Thread Steven D'Aprano
On Tue, 24 Jul 2012 09:47:38 +0200, Ulrich Eckhardt wrote:

> [0] Note that in almost all cases, when referring to a tag, Python
> implicitly operates on the object attached to it. One case (the only
> one?) where it doesn't is the "del" statement.

Name-binding:

x = 1

operates on the name "x", not the object. The object 1 does not know it 
has been bound to anything -- that's one weakness of the "tag" model, 
because it implies that objects know what tags they have attached. They 
don't.

Imports:

import x

also operates on the name x and not the object.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Gender, Representativeness and Reputation in StackOverflow

2012-07-24 Thread Steven D'Aprano
On Mon, 23 Jul 2012 22:56:42 -0700, rusi wrote:

>> On Mon, 23 Jul 2012 22:51:07 -0400, Devin Jeanpierre wrote:
>> > When people boycott a product, it isn't because not having the
>> > product is better than having the product. That's clearly untrue:
>> > despite the reasons for the boycott, the product has some value. They
>> > boycott it because by doing so, they can get something better than
>> >  or  -- they can get > > badness>. (At least, in theory :)
>>
>>
> On Jul 24, 10:34 am, Steven D'Aprano  +comp.lang.pyt...@pearwood.info> wrote:
>> I don't think that's why people boycott products. I think that boycotts
>> are a clear example of people making a moral decision to punish
>> somebody for doing wrong, even at the cost to themselves. Sometimes
>> significant costs, as in missing out altogether.
>>
>>
> I dont see so much difference -- maybe you missed the 'badness' in
> Devin's quote?

No, I saw it. The difference is that I read Devin as suggesting that 
people are motivated by a sense of "I want to get Product X, without the 
badness", which implies that the primary driving force is "get Product 
X", rather than "avoid badness". In a sense, Devin suggests that boycotts 
are a form of bargaining: give us a better product by reducing the 
badness, and we'll buy. (Whether Devin *intended* this implication is 
another question.)

I'm suggesting that the primary motivation is "this company is doing bad, 
I wish to punish them by withholding my purchases, even to my own 
detriment". I'm suggesting that, at least to some degree, people are 
*not* bargaining for better products when they engage in a boycott. They 
are punishing a cheater, and to some degree they may never quite forgive 
and forget.

I can't speak for others, but 30(?) years later, I still sometimes 
consciously forgo buying Nestle products because of their unethical 
promotion of expensive baby formula at the expense of breast-feeding in 
Africa. As time goes by, this urge becomes weaker, but it never quite 
goes away.

A more relevant example might be the way many people in the FOSS 
community do not and will not forgive Microsoft for their bad behaviour 
in the past, even now that they have mostly, and reluctantly, accepted 
that they have to coexist with Linux.

Or this: http://xkcd.com/1057/

Of course, people are complex and their motivations can be a tangled web 
of contradictory and complimentary urges. But "punish the cheater" is an 
extremely powerful motivation in human beings.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-24 Thread Thomas Rachel

Am 23.07.2012 16:50 schrieb Stone Li:

I'm totally confused by this code:

Code:

a = None
b = None
c = None
d = None
x = [[a,b],
  [c,d]]
e,f = x[1]
print e,f
c = 1
d = 2
print e,f
e = 1
f = 2
print c,d

Output:

None None
None None
1 2


I'm expecting the code as:

None None
1 2
1 2


What's wrong?


Your expectation :-)

With c = 1 and d = 2 you do not change the respective objects, but you 
assign other objects to the same names.


The old content is still contained in x[1].

If you would only modify these objects (not possible as ints are 
immutable), you would notice the changes here and there.



Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of r`.......`

2012-07-24 Thread Thomas Rachel

Am 23.07.2012 17:59 schrieb Steven D'Aprano:

>> Before you

get a language that uses full Unicode, you'll need to have fairly
generally available keyboards that have those keys.


Or at least keys or key combinations for the stuff you need, which might 
differ e. g. with the country you live in. There are countries which 
have keyboards with äöüß, others with èàéî, and so on.




Or sensible, easy to remember mnemonics for additional characters. Back
in 1984, Apple Macs made it trivial to enter useful non-ASCII characters
from the keyboard. E.g.:

Shift-4 gave $
Option-4 gave ¢
Option-c gave ©
Option-r gave ®


So what? If I type Shift-3 here, I get a § (U+00A7). And the ° (U+00B0) 
comes with Shift-^, the µ (U+00B5) with AltGr-M and the € sign with AltGr+E.



Dead-keys made accented characters easy too:

Option-u o gave ö
Option-u e gave ë



And if I had a useful OS here at work, I even could use the compose key 
to produce many other non-ASCII characters. To be able to create each 
and every of them is not needed in order to have support for them in a 
language, just the needed ones.


Useful editors use them as well, although you have not all of them on 
your keyboard.



Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-24 Thread Ian Kelly
On Mon, Jul 23, 2012 at 7:19 PM, Andrew Cooper  wrote:
> Python is a statically scoped language, whereas the functionality you
> are expecting would be an example of dynamically scoped.

While it's true that Python is statically scoped, that has nothing at
all to do with the code from the OP's question, which contains only
one (global) scope anyway.

The real issue is confusion between name binding and object mutation.
By reassigning c and d, the OP is evidently trying to mutate the list
named x (or to be more precise, the list that is the second element of
the list named x).  But this doesn't work, because name-binding
doesn't mutate objects as it does in languages with variable semantics
(C, for example); it merely rebinds the names to different objects.  c
and d end up bound to values that weren't in the list to begin with,
meanwhile the list remains unchanged and e and f are still just bound
to None.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-24 Thread Thomas Rachel

Am 24.07.2012 09:47 schrieb Ulrich Eckhardt:


[0] Note that in almost all cases, when referring to a tag, Python
implicitly operates on the object attached to it. One case (the only
one?) where it doesn't is the "del" statement.


The del and the =, concerning the left side.

But even those don't do that under all circumstances. Think about 
__setitem__, __setattr__, __set__, __delitem__, __delattr__, __delete__.



Thomas



--
http://mail.python.org/mailman/listinfo/python-list


Re: groveling over a file for Q:: and A:: stmts

2012-07-24 Thread paul618
Hi Steve:


Thank you for your quick response.  

Ah, indeed I failed to ask my question::  Why doesnt this code print the 
sampledata?  Instead it prints the empty list.

The answer is probably quite simple, as I really am an idiot.


Thanks again,
paul


-- 
http://mail.python.org/mailman/listinfo/python-list


How to represent dates BC

2012-07-24 Thread Laszlo Nagy

>>> import datetime
>>> old_date = datetime.date(1,12,31)
>>> str(old_date)
'0001-12-31'
>>> one_year = datetime.timedelta(days=365)
>>> str(one_year)
'365 days, 0:00:00'
>>> old_date - 10*one_year
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: date value out of range
>>>


My main problem is that I have an application that stores dates in a 
PostgreSQL database. The PostgreSQL date type is capable of storing 
dates from 4713 BC to 294276 AD.


http://www.postgresql.org/docs/9.2/static/datatype-datetime.html

The application itself stores historical data of events. Apparently, the 
Python datetime.date object cannot handle dates before 1 AD. The 
psycopg2 driver converts date values to date objects. But not in this case:


>>> conn = dbpool.borrow("central")
>>> conn.getqueryvalue("select '1311-03-14 BC'::date")
Traceback (most recent call last):
  File "", line 1, in 
 (some more tracelog here).
data = cur.fetchone()
ValueError: year is out of range
>>>

What is the good solution? I could - in theory - store the dates in a 
text field, but then I won't be able to create incides on dates, 
add/substract with other date values etc.


I could try to always use something like:

select extract(year from date_field) as year,extract(month from 
date_field) as month,extract(day from date_field) as day 


but this is really messy!

What is the good representation here? Should I implement my own date 
type? (I wouldn't want to.)


Thanks,

  Laszlo

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to deal with python 32bit memory error

2012-07-24 Thread Dave Angel
On 07/24/2012 04:06 AM, Sammy Danso wrote:
> Hello Experts,
> I am having a 'memory error',

Please post the actual error message.

>  which suggest that I 
> have run out of memory, but I am not sure this is the case as I have 
> considerable amount of memory unused on my computer. 

What OS, version, and bitness.  What 32bit Python?

How do you know you have unused memory?  How much total memory, how much
swapspace, and what are you using to tell how much of each is unused?

How big is the process when it dies?  And how are you determining that?

> A little 
> search suggest this is a limitation of python 32 and an option is to 
> have a 64bit. I however have other plug-ins, which are tied to the 32bit
>  so this is not the best option in my case. 
There are some limitations to 32 bits, that have nothing to do with
Python specifically.  However, they have different impact, depending on
the environment you're running in.  First and foremost, address are
32bits, which limits them to 4gb of ram.  So out of your 32Gig of
swapspace, a best-case maximum regardless of OS is 4Gig.  No operating
system lets you actually get that high.

> I was wondering whether there is an elegant way to dealing with this without 
> installing a 6bit version of python.

The most elegant way of solving it is to reduce the amount of memory
your program is using.  For example, instead of building large lists,
perhaps you can use generators.  Simplest example (for Python 2.x) is
xrange rather than range.

For another example, reduce the globals.  Create large objects inside a
limited function, and discard them when done (by returning from the
function).

> Thanks very much in advance.
> Sammy
>

When responding, please remember to post your response *AFTER* the part
you're quoting.  Most of your previous posts here have been top-posted.

-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-24 Thread Ulrich Eckhardt

Am 24.07.2012 10:24, schrieb Chris Angelico:

On Tue, Jul 24, 2012 at 5:47 PM, Ulrich Eckhardt
 wrote:

There is one model that has helped me much understanding how Python ticks
and that is the model of name tags. The code "a = 1" creates an integer with
value 1 and attaches a tag with "a" written on it using a small piece of
rope.


A double strand of rope, I think. If it were one strand, we'd write "a - 1". :)


Two fibers, possibly twisted let's call it string!

I really had to think about how to call the thing while avoiding the 
term string in order not to add to the confusion...


(:

Uli
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to represent dates BC

2012-07-24 Thread Christian Heimes
Am 24.07.2012 11:55, schrieb Laszlo Nagy:
> What is the good representation here? Should I implement my own date
> type? (I wouldn't want to.)

JDN [1] is a commonly used format for wide ranges of dates. I've used it
in the past to refer to days BC. PyPI offers a Python module [2] that
looks well written and documented.

HTH,
Christian

[1] http://en.wikipedia.org/wiki/Julian_Day_Number
[2] http://pypi.python.org/pypi/jdcal/1.0


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to deal with python 32bit memory error

2012-07-24 Thread Christian Heimes
Am 24.07.2012 11:58, schrieb Dave Angel:
> There are some limitations to 32 bits, that have nothing to do with
> Python specifically.  However, they have different impact, depending on
> the environment you're running in.  First and foremost, address are
> 32bits, which limits them to 4gb of ram.  So out of your 32Gig of
> swapspace, a best-case maximum regardless of OS is 4Gig.  No operating
> system lets you actually get that high.

The usable amount of memory is much lower than 4 GB for a 32bit program.
A typical program can use about 2.4 to 2.7 GB virtual address space for
heap. The exact amount is hard to predicate as it depends on the
operating system, memory allocator and other settings. The rest of the 4
GB virtual address space is reserved for stack, mapping of dynamic
libraries and operating system routines.

The amount of usable memory on the heap (area returned by malloc()) is
often lowered by memory fragmentation. If your program tries to malloc
100 MB of memory but the largest contiguous area is just 98 MB you'll
get a memory error, too.

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: My first ever Python program, comments welcome

2012-07-24 Thread Lipska the Kat

On 24/07/12 06:13, rusi wrote:

On Jul 22, 10:23 pm, Lipska the Kat  wrote:


Heh heh, Nothing to do with Eclipse, just another thing to get my head
around. For work and Java IMHO you can't beat eclipse...
at the moment I'm getting my head around git,


Bumped into this yesterday. Seems like a good aid to git-comprehension
https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh


eek ... now that's a shell script to be proud of isn't it .. and it 
works [lipska@ubuntu fileio (master)]$ impressive. Good find, thanks.



reminding myself of C, learning Python
and re-learning make. Enough already; but if there's a python plugin I
guess I'll get around to it eventually


Seems like a strange combo. It should be
(C&make)|(python&X)|(Java&Ant)
where X could range from


%-}


Setup http://docs.python.org/distutils/setupscript.html
to distribute http://guide.python-distribute.org/
to scons http://www.scons.org/


Well that's the joy of life in semi-retirement. I can do as I please
I read something somewhere the other day about living longer if you 
retire early, well I retired early but if I live another 50 years it 
won't be long enough to learn everything I want to.


Java&Ant everyday
C&make   a while back

python& well I sort of got sidetracked by python
... and then I got sidetracked by git !!!

Lipska

--
Lipska the Kat: Troll hunter, Sandbox destroyer
and Farscape dreamer of Aeryn Sun.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to represent dates BC

2012-07-24 Thread Laszlo Nagy

On 2012-07-24 12:29, Christian Heimes wrote:

Am 24.07.2012 11:55, schrieb Laszlo Nagy:

What is the good representation here? Should I implement my own date
type? (I wouldn't want to.)

JDN [1] is a commonly used format for wide ranges of dates. I've used it
in the past to refer to days BC. PyPI offers a Python module [2] that
looks well written and documented.
It was really useful, thanks. I also figured out how to convert julian 
date to timestamp in postgresql:


|to_date(2455452::text,  'J')
|

So it is possible to create incides.

   L

-- 
http://mail.python.org/mailman/listinfo/python-list


Daemon loses __file__ reference after a while.

2012-07-24 Thread ivdn...@gmail.com
Hello,

I have a daemon process that runs for a considerable amount of time (weeks on 
end) without any problems. At some point I start getting the exception:

Exception info: Traceback (most recent call last):
  File "scheduler.py", line 376, in applyrule
result = execrule(rule_code)
  File "scheduler.py", line 521, in execrule
rulepath = 
os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
NameError: name '__file__' is not defined

This section of the code is executed in this process *all the time*, but 
suddenly stops working. I have been searching for similar issues online, but 
only come accross people having problems because they run the script 
interactively. This is not the case here.

I am running python from a virtual-env installation from a stock Red Hat EL 6.2 
installation:

(virtual-env)[user@host ~]$ python --version
Python 2.6.6
(virtual-env)[user@host ~]$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.2 (Santiago)

I would greatly appreciate any pointers on where to start looking to find the 
problem.

Ian.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: groveling over a file for Q:: and A:: stmts

2012-07-24 Thread MRAB

On 24/07/2012 08:50, paul618 wrote:

#!/usr/bin/env python
# grep_for_QA.py  I am only looking to isolate uniq Q:: and A:: stmts from my 
daily files
#
# note:  This algorithm will fail if there are any blank lines within the Q and 
A area of interest (a paragraph)

# D. Beazley is my fav documentation

import re, glob
import pprint as pp

sampledata = '''
A:: And Straight Street is playin on the Radio Free Tibet.  What are the 
chances, DTMB?
Q:: About 1 in 518400, Professor.
A:: Correct!  Err, I thought it was 1:410400, but close enough for jazz!


'''

pattern0 = re.compile("Q::")
pattern1 = re.compile("A::")  # objects of interest can start with A:: ;; not 
alway Q::
END_OF_PARAGRAPH_pat = "\n\s*\n"

path = "/Users/paultaney/dailies2012/0722" # an example of real data set.

toggle = False
L = []
M = []

#file = open(path, "r")
try:
 #for line in file.readlines():
 for line in sampledata:


sampledata is a string, therefore this is iterating over the string,
which yields characters, not lines. Try using sampledata.splitlines():

for line in sampledata.splitlines():


 try:
 # Later, I also need to treat Unicode -- and I am clueless.

 # falsestarts::
 #line.encode("utf8").decode('xxx', 'ignore')
 #line.encode("utf8", 'ignore')
 #line.decode('8859')
 #line.decode('8859')  # 8859, Latin-1 doesn't cover my  CJK 
pastings  AT ALL
 #line.decode('GB18030')  # 171006 -- ack
 #encoded_line = line  # xxx line.encode("utf8")

 mo0 = re.search(pattern0, line)


This searches for pattern0 anywhere in the line. You really want to
check whether the line starts with pattern0, which is better done with:

line.startswith("Q::")


 mo1 = re.search(pattern1, line)
 mo2 = re.search(END_OF_PARAGRAPH_pat, line)

 if mo0:
 if 1: print ("I see pattern 0")
 toggle = True
 if 1: print(line)
 M.append(mo0.group())

 if mo1:
 if 1: print ("I see pattern 1")
 toggle = True
 M.append(mo1.group())

 if mo2 and toggle:
 if 1: print ("I see pattern 2 AND toggle is set")
 # got one.  save it for uniqifying, and empty the container
 toggle = False
 L.append(M)
 M = []

 except Exception as e:
 print("--- " + e + " ---")

except UnicodeDecodeError:
 #encoded_line = encoded_line.urlsafe_b64encode(re.replace("asdf", 
encoded_line))
 #line = re.sub(".+", "--- asdf ---", line)
 pass

L.sort
print (L)

# and what"s wrong with some of this, here!
#myHash = set(L)# uniqify
#pp.pprint(myHash)  # july 23, 131001 hike!



--
http://mail.python.org/mailman/listinfo/python-list


Daemon loses __file__ reference after a while

2012-07-24 Thread ivdn...@gmail.com
Hello all,

I have a deamon process that runs for some considerable time (weeks) without 
any problems. At some point it starts throwing the following exception:

  File "/some/path/scheduler.py", line 376, in applyrule
result = execrule(rule_code)
  File "/some/path/scheduler.py", line 521, in execrule
rulepath = 
os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
NameError: name '__file__' is not defined

This section is executed *all the time* but somehow stops working after a 
while. I have searched the web and this group, but can only find references to 
this occurring when run interactively, which is not the case here. When I 
restart the process the problem, at least temporarily, disappears.

I am running the script in a virtual-env on a stock Red Hat EL 6.2 installation:

(my-env)[user@host ~]$ python --version
Python 2.6.6
(my-env)[user@host ~]$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.2 (Santiago)

Thank you very much in advance for any pointers as to where to start looking to 
find the problem.

Ian.

(If this post occurs twice, I apologize. Google groups was complaining about my 
post taking long to process and to wait a few minutes and try again if it 
didn't show up, which as far as I can determine, it didn't.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Ervin Hegedüs
hello,

On Tue, Jul 24, 2012 at 04:48:42AM -0700, ivdn...@gmail.com wrote:
> Hello,
> 
> I have a daemon process that runs for a considerable amount of time (weeks on 
> end) without any problems. At some point I start getting the exception:
> 
> Exception info: Traceback (most recent call last):
>   File "scheduler.py", line 376, in applyrule
> result = execrule(rule_code)
>   File "scheduler.py", line 521, in execrule
> rulepath = 
> os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
> NameError: name '__file__' is not defined
> 
> This section of the code is executed in this process *all the time*, but 
> suddenly stops working. I have been searching for similar issues online, but 
> only come accross people having problems because they run the script 
> interactively. This is not the case here.

could you send the relevant part of the code?

I mean: how do you daemonize your process?
 
> I am running python from a virtual-env installation from a stock Red Hat EL 
> 6.2 installation:
> 
> (virtual-env)[user@host ~]$ python --version
> Python 2.6.6
> (virtual-env)[user@host ~]$ cat /etc/redhat-release 
> Red Hat Enterprise Linux Server release 6.2 (Santiago)

If you use fork(), it drops all file descriptors, and creates new
ones - may be then loss the __file__...?


a.


-- 
I � UTF-8
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while

2012-07-24 Thread Laszlo Nagy

On 2012-07-24 14:17, ivdn...@gmail.com wrote:

Hello all,

I have a deamon process that runs for some considerable time (weeks) without 
any problems. At some point it starts throwing the following exception:

   File "/some/path/scheduler.py", line 376, in applyrule
 result = execrule(rule_code)
   File "/some/path/scheduler.py", line 521, in execrule
 rulepath = 
os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
NameError: name '__file__' is not defined
It is not a direct solution to your problem, but can you save the value 
of os.path.dirname(__file__) into another variable?


--
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Laszlo Nagy



If you use fork(), it drops all file descriptors, and creates new
ones - may be then loss the __file__...?

I don't think this is the case. He wrote that the process runs for weeks 
without problems, and code using __file__ is being executed all the time.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread ivdn...@gmail.com
On Tuesday, July 24, 2012 2:24:31 PM UTC+2, Ervin Hegedüs wrote:
> hello,
> 
> On Tue, Jul 24, 2012 at 04:48:42AM -0700, ivdn...@gmail.com wrote:
> > Hello,
> > 
> > I have a daemon process that runs for a considerable amount of time 
> (weeks on end) without any problems. At some point I start getting the 
> exception:
> > 
> > Exception info: Traceback (most recent call last):
> >   File "scheduler.py", line 376, in applyrule
> > result = execrule(rule_code)
> >   File "scheduler.py", line 521, in execrule
> > rulepath = 
> os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
> > NameError: name '__file__' is not defined
> > 
> > This section of the code is executed in this process *all the time*, but 
> suddenly stops working. I have been searching for similar issues online, but 
> only come accross people having problems because they run the script 
> interactively. This is not the case here.
> 
> could you send the relevant part of the code?
> 
> I mean: how do you daemonize your process?

It's done by a double fork:

## First fork()
pid = os.fork()
if pid != 0: sys.exit(0) # parent exits.

## create new session
os.setsid()
   
## ignore SIGHUP
signal.signal(signal.SIGHUP, signal.SIG_IGN)

## Second fork()
pid = os.fork()
if pid != 0: sys.exit(0) # First child exits.
   
## Change working directory to the home directory.
homedir = pwd.getpwuid(os.geteuid())[5]
os.chdir(homedir)

os.umask(0)

for fd in range(0, 1024):
try:
os.close(fd)
except:
pass # fd not open, ignore this exception.

The original C version of this code is from W.R. Stevens' daemon_init() routine 
in "UNIX Network Programming Volume 1, second edition"

>  
> > I am running python from a virtual-env installation from a stock Red Hat 
> EL 6.2 installation:
> > 
> > (virtual-env)[user@host ~]$ python --version
> > Python 2.6.6
> > (virtual-env)[user@host ~]$ cat /etc/redhat-release 
> > Red Hat Enterprise Linux Server release 6.2 (Santiago)
> 
> If you use fork(), it drops all file descriptors, and creates new
> ones - may be then loss the __file__...?

I doubt this would be it, or it would stop working immediately, since 
daemonization is done upon startup of the process. File descriptors are closed 
immediately upon startup, it doesn't seem to affect the reference to the 
__file__ string (which is not a file object, but a str object)

> 
> 
> a.
> 
> 
> -- 
> I � UTF-8



On Tuesday, July 24, 2012 2:24:31 PM UTC+2, Ervin Hegedüs wrote:
> hello,
> 
> On Tue, Jul 24, 2012 at 04:48:42AM -0700, ivdn...@gmail.com wrote:
> > Hello,
> > 
> > I have a daemon process that runs for a considerable amount of time 
> (weeks on end) without any problems. At some point I start getting the 
> exception:
> > 
> > Exception info: Traceback (most recent call last):
> >   File "scheduler.py", line 376, in applyrule
> > result = execrule(rule_code)
> >   File "scheduler.py", line 521, in execrule
> > rulepath = 
> os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
> > NameError: name '__file__' is not defined
> > 
> > This section of the code is executed in this process *all the time*, but 
> suddenly stops working. I have been searching for similar issues online, but 
> only come accross people having problems because they run the script 
> interactively. This is not the case here.
> 
> could you send the relevant part of the code?
> 
> I mean: how do you daemonize your process?
>  
> > I am running python from a virtual-env installation from a stock Red Hat 
> EL 6.2 installation:
> > 
> > (virtual-env)[user@host ~]$ python --version
> > Python 2.6.6
> > (virtual-env)[user@host ~]$ cat /etc/redhat-release 
> > Red Hat Enterprise Linux Server release 6.2 (Santiago)
> 
> If you use fork(), it drops all file descriptors, and creates new
> ones - may be then loss the __file__...?
> 
> 
> a.
> 
> 
> -- 
> I � UTF-8

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while

2012-07-24 Thread ivdn...@gmail.com
On Tuesday, July 24, 2012 2:29:19 PM UTC+2, Laszlo Nagy wrote:
> On 2012-07-24 14:17, ivdn...@gmail.com wrote:
> > Hello all,
> >
> > I have a deamon process that runs for some considerable time (weeks) 
> without any problems. At some point it starts throwing the following 
> exception:
> >
> >File "/some/path/scheduler.py", line 376, in applyrule
> >  result = execrule(rule_code)
> >File "/some/path/scheduler.py", line 521, in execrule
> >  rulepath = 
> os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
> > NameError: name '__file__' is not defined
> It is not a direct solution to your problem, but can you save the value 
> of os.path.dirname(__file__) into another variable?


That might be a workaround that I'm seriously pondering as well.

Thank you.

Ian.

(sorry for google messing up my posts)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Chris Angelico
On Tue, Jul 24, 2012 at 1:56 AM, John Gordon  wrote:
> In  Mark Lawrence 
>  writes:
>
>> Sorry not with you is there something special about April 1st next year?
>
> In the United States, April 1st (also known as April Fool's Day) is an
> occasion for practical jokes, faked 'news' stories, and general silliness.
>
> I don't know if it is observed outside the U.S.

It is, in many places. It's one of the few truly international
holidays. The next nearest, Pi Day, has two different dates (the
American and the European - of course, here in Australia, we celebrate
both).

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Gender, Representativeness and Reputation in StackOverflow

2012-07-24 Thread Chris Angelico
On Tue, Jul 24, 2012 at 12:51 PM, Devin Jeanpierre
 wrote:
> When people boycott a product, it isn't because not having the product
> is better than having the product. That's clearly untrue: despite the
> reasons for the boycott, the product has some value.

That's because you don't call it boycotting when the product has no
value. I'm not in the habit of purchasing used cigarette ash, and I
suspect you're not buying any either, but that's not a boycott.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Devin Jeanpierre
On Mon, Jul 23, 2012 at 12:09 PM, Chris Angelico  wrote:
> It is, in many places. It's one of the few truly international
> holidays. The next nearest, Pi Day, has two different dates (the
> American and the European - of course, here in Australia, we celebrate
> both).

Here in Canada we celebrate Tau day.

-- Devin

(... I wish.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ben Finney
Chris Angelico  writes:

> […] Pi Day, has two different dates (the American and the European -
> of course, here in Australia, we celebrate both).

What would be the two days? The 14th day of the 3rd month, and, um,
what?

Or do you Australians have the third day of the fourteenth month?

-- 
 \  “Earth gets its price for what Earth gives us.” —James Russell |
  `\Lowell |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Chris Angelico
On Wed, Jul 25, 2012 at 12:35 AM, Ben Finney  wrote:
> Chris Angelico  writes:
>
>> […] Pi Day, has two different dates (the American and the European -
>> of course, here in Australia, we celebrate both).
>
> What would be the two days? The 14th day of the 3rd month, and, um,
> what?

Americans celebrate March 14th as 3.14; some Europeans celebrate July
22nd as 22/7 (which is 3.142857, fairly close to 3.14159). We claim
both, and also June 28th (aka Tau Day or Two Pi Day, 6.28).

> Or do you Australians have the third day of the fourteenth month?

The extra months would explain why we're ever so much more productive
than the rest of the world! Now if only we could be productive at more
than just dole bludging...

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Dieter Maurer
"ivdn...@gmail.com"  writes:

> I have a daemon process that runs for a considerable amount of time (weeks on 
> end) without any problems. At some point I start getting the exception:
>
> Exception info: Traceback (most recent call last):
>   File "scheduler.py", line 376, in applyrule
> result = execrule(rule_code)
>   File "scheduler.py", line 521, in execrule
> rulepath = 
> os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
> NameError: name '__file__' is not defined
>
> This section of the code is executed in this process *all the time*, but 
> suddenly stops working. I have been searching for similar issues online, but 
> only come accross people having problems because they run the script 
> interactively. This is not the case here.

This is strange indeed.

I have only one vague idea: should something try to terminate the
process, modules would start to lose their variables during shutdown.

-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.6 StreamReader.readline()

2012-07-24 Thread cpppwner
Hi,

I have a simple question, I'm using something like the following lines in 
python 2.6.2

reader = codecs.getreader(encoding)
lines  =  []
with open(filename, 'rb') as f:
lines  = reader(f, 'strict').readlines(keepends=False)

where encoding == 'utf-16-be'
Everything works fine, except that lines[0] is equal to codecs.BOM_UTF16_BE
Is this behaviour correct, that the BOM is still present?

Thanks in advance for your help.

Best,
Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Maarten
On Tuesday, July 24, 2012 4:35:29 PM UTC+2, Ben Finney wrote:
> Chris Angelico writes:
> 
> > […] Pi Day, has two different dates (the American and the European -
> > of course, here in Australia, we celebrate both).
> 
> What would be the two days? The 14th day of the 3rd month, and, um,
> what?
> 
> Or do you Australians have the third day of the fourteenth month?

You just missed it:
22/7

Maarten
-- 
http://mail.python.org/mailman/listinfo/python-list


HMM and CRF Package

2012-07-24 Thread subhabangalore
Dear Group,

I was looking for the following solutions.

(i) a Python Hidden Markov Model(HMM) library.
(ii)a Python Conditional Random Field(CRF) library.
(iii) I am using Python 3.2.1 on Windows 7(64 bit) and also like to get a NLTK 
version.
(iv) I may use unicode character as input.

If any one may kindly help me out. 

Best Regards,
Subhabrata Banerjee.
Gurgaon.
India. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 8:50 AM, Chris Angelico  wrote:
> Americans celebrate March 14th as 3.14; some Europeans celebrate July
> 22nd as 22/7 (which is 3.142857, fairly close to 3.14159). We claim
> both, and also June 28th (aka Tau Day or Two Pi Day, 6.28).

Hey now, Tau Day is an American invention, so no claiming it as an
Australian thing.  We just need to get a few more people here to start
observing it; that's all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Chris Angelico
On Wed, Jul 25, 2012 at 2:36 AM, Ian Kelly  wrote:
> On Tue, Jul 24, 2012 at 8:50 AM, Chris Angelico  wrote:
>> Americans celebrate March 14th as 3.14; some Europeans celebrate July
>> 22nd as 22/7 (which is 3.142857, fairly close to 3.14159). We claim
>> both, and also June 28th (aka Tau Day or Two Pi Day, 6.28).
>
> Hey now, Tau Day is an American invention, so no claiming it as an
> Australian thing.  We just need to get a few more people here to start
> observing it; that's all.

I never did. We celebrate it as Two Pi Day here. You're most welcome
to lay claim to its invention, as long as you release it under an
acceptable Free license. Of course, you're legitimately able to put
non-commercial clauses in (after what happened to Christmas, I
wouldn't blame you), but we'd just have to invent our own day to
celebrate instead. The calendar perceives censorship as damage, and
routes around it...

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ethan Furman

Ian Kelly wrote:

On Tue, Jul 24, 2012 at 8:50 AM, Chris Angelico  wrote:

Americans celebrate March 14th as 3.14; some Europeans celebrate July
22nd as 22/7 (which is 3.142857, fairly close to 3.14159). We claim
both, and also June 28th (aka Tau Day or Two Pi Day, 6.28).


Hey now, Tau Day is an American invention, so no claiming it as an
Australian thing.  We just need to get a few more people here to start
observing it; that's all.


I'm in!  At least for next year.  Assuming I remember...

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


no data exclution and unique combination.

2012-07-24 Thread giuseppe . amatulli
Hi,
would like to take eliminate a specific number in an array and its 
correspondent in an other array, and vice-versa. 

given 

a=np.array([1,2,4,4,5,4,1,4,1,1,2,4])
b=np.array([1,2,3,5,4,4,1,3,2,1,3,4])

no_data_a=1
no_data_b=2

a_clean=array([4,4,5,4,4,4])
b_clean=array([3,5,4,4,3,4])

after i need to calculate unique combination in pairs to count the observations 
and obtain
(4,3,2)
(4,5,1)
(5,4,1)
(4,4,2)

For the fist task i did

a_No_data_a = a[a != no_data_a]
b_No_data_a = b[a != no_data_a]

b_clean = b_No_data_a[b_No_data_a != no_data_b]
a_clean  = a_No_data_a[a_No_data_a != no_data_b]

but the results are not really stable. 

For the second task 
The np.unique would solve the problem if it can be apply to a two arrays.

Any idea?
thanks in advance 
Giuseppe




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no data exclution and unique combination.

2012-07-24 Thread MRAB

On 24/07/2012 19:27, giuseppe.amatu...@gmail.com wrote:

Hi,
would like to take eliminate a specific number in an array and its 
correspondent in an other array, and vice-versa.

given

a=np.array([1,2,4,4,5,4,1,4,1,1,2,4])
b=np.array([1,2,3,5,4,4,1,3,2,1,3,4])

no_data_a=1
no_data_b=2

a_clean=array([4,4,5,4,4,4])
b_clean=array([3,5,4,4,3,4])

after i need to calculate unique combination in pairs to count the observations
and obtain
(4,3,2)
(4,5,1)
(5,4,1)
(4,4,2)

For the fist task i did

a_No_data_a = a[a != no_data_a]
b_No_data_a = b[a != no_data_a]

b_clean = b_No_data_a[b_No_data_a != no_data_b]
a_clean  = a_No_data_a[a_No_data_a != no_data_b]

but the results are not really stable.


mask = (a != no_data_a) & (b != no_data_b)
a_clean = a[mask]
b_clean = b[mask]


For the second task
The np.unique would solve the problem if it can be apply to a two arrays.



--
http://mail.python.org/mailman/listinfo/python-list


Re: no data exclution and unique combination.

2012-07-24 Thread MRAB

On 24/07/2012 19:51, MRAB wrote:

On 24/07/2012 19:27, giuseppe.amatu...@gmail.com wrote:

Hi,
would like to take eliminate a specific number in an array and its 
correspondent in an other array, and vice-versa.

given

a=np.array([1,2,4,4,5,4,1,4,1,1,2,4])
b=np.array([1,2,3,5,4,4,1,3,2,1,3,4])

no_data_a=1
no_data_b=2

a_clean=array([4,4,5,4,4,4])
b_clean=array([3,5,4,4,3,4])

after i need to calculate unique combination in pairs to count the observations
and obtain
(4,3,2)
(4,5,1)
(5,4,1)
(4,4,2)

For the fist task i did

a_No_data_a = a[a != no_data_a]
b_No_data_a = b[a != no_data_a]

b_clean = b_No_data_a[b_No_data_a != no_data_b]
a_clean  = a_No_data_a[a_No_data_a != no_data_b]

but the results are not really stable.


mask = (a != no_data_a) & (b != no_data_b)
a_clean = a[mask]
b_clean = b[mask]


For the second task
The np.unique would solve the problem if it can be apply to a two arrays.


I couldn't figure out how to do the second part in numpy, so:

from collections import Counter
counts = Counter(zip(a_clean, b_clean))
counts = [pair + (count,) for pair, count in counts.items()]

--
http://mail.python.org/mailman/listinfo/python-list


Re: no data exclution and unique combination.

2012-07-24 Thread Ian Kelly
On Jul 24, 2012 12:32 PM,  wrote:

> after i need to calculate unique combination in pairs to count the
observations
> and obtain
> (4,3,2)
> (4,5,1)
> (5,4,1)
> (4,4,2)

I don't know about a numpy solution, but this could be achieved by
collections.Counter(zip(a, b)).items(). That gives you:
((4,3),2)
((4,5),1)
Etc.

If you really want triples instead of pair-value pairs, then you would need
to flatten the tuples yourself.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no data exclution and unique combination.

2012-07-24 Thread Terry Reedy

On 7/24/2012 2:27 PM, giuseppe.amatu...@gmail.com wrote:

Hi,
would like to take eliminate a specific number in an array and its 
correspondent in an other array, and vice-versa.

given

a=np.array([1,2,4,4,5,4,1,4,1,1,2,4])
b=np.array([1,2,3,5,4,4,1,3,2,1,3,4])

no_data_a=1
no_data_b=2

a_clean=array([4,4,5,4,4,4])
b_clean=array([3,5,4,4,3,4])


As I discovered when running the solution before, your test data are 
wrong, leaving out 2,3 before the last pair (4,4). Anyway, for those 
interested in a plain Python solution, without numpy:


a=[1,2,4,4,5,4,1,4,1,1,2,4]
b=[1,2,3,5,4,4,1,3,2,1,3,4]

no_data_a=1
no_data_b=2

a_clean=(4,4,5,4,4,2,4)
b_clean=(3,5,4,4,3,3,4)

cleaned = list(zip(*(pair for pair in zip(a,b)
if pair[0] != no_data_a and pair[1] != no_data_b)))
print(cleaned, cleaned == [a_clean, b_clean])
#
[(4, 4, 5, 4, 4, 2, 4), (3, 5, 4, 4, 3, 3, 4)] True


--
Terry Jan Reedy



--
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Paul Rubin
Dieter Maurer  writes:
> I have only one vague idea: should something try to terminate the
> process, modules would start to lose their variables during shutdown.

That happens all the time with multi-threaded programs, because the
shutdown is happening concurrently with other threads doing stuff.  Are
there threads in this particular program?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 8:59 AM, Dieter Maurer  wrote:
> "ivdn...@gmail.com"  writes:
>
>> I have a daemon process that runs for a considerable amount of time (weeks 
>> on end) without any problems. At some point I start getting the exception:
>>
>> Exception info: Traceback (most recent call last):
>>   File "scheduler.py", line 376, in applyrule
>> result = execrule(rule_code)
>>   File "scheduler.py", line 521, in execrule
>> rulepath = 
>> os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
>> NameError: name '__file__' is not defined
>>
>> This section of the code is executed in this process *all the time*, but 
>> suddenly stops working. I have been searching for similar issues online, but 
>> only come accross people having problems because they run the script 
>> interactively. This is not the case here.
>
> This is strange indeed.
>
> I have only one vague idea: should something try to terminate the
> process, modules would start to lose their variables during shutdown.

That's a good theory.  Or perhaps something in the code itself is
handling the module's globals() and very occasionally does something
that is incorrect and destructive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 1:32 PM, Paul Rubin  wrote:
> Dieter Maurer  writes:
>> I have only one vague idea: should something try to terminate the
>> process, modules would start to lose their variables during shutdown.
>
> That happens all the time with multi-threaded programs, because the
> shutdown is happening concurrently with other threads doing stuff.  Are
> there threads in this particular program?

It also comes up in single-threaded programs that use finalizers
(__del__ methods).  At the time an object is finalized, many globals
might already be gone.
-- 
http://mail.python.org/mailman/listinfo/python-list


assert expressions

2012-07-24 Thread Wanderer
If I use the code 

assert False, "unhandled option"

I get output like:

option -q not recognized
for help use --help

What other expressions can I use other than "unhandled option"? Is there a list 
somewhere?

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 1:57 PM, Wanderer  wrote:
> If I use the code
>
> assert False, "unhandled option"
>
> I get output like:
>
> option -q not recognized
> for help use --help
>
> What other expressions can I use other than "unhandled option"? Is there a 
> list somewhere?

Are you using argparse or optparse or getopt or something else
altogether?  And where are you placing this assert?  It would be
helpful to see some actual code to understand what you are doing.

And by the way, assert is a very bad way to check user input or to
unconditionally raise an exception.  The reason is that if Python is
invoked with -O, then all assertions are removed from the compiled
bytecode, and then your unconditional exception code doesn't raise any
exception at all.  If you want to raise an exception, just do it:

raise Exception("unhandled option")

Ideally, you would also subclass Exception to create a more specific
exception class for your custom exception:

class UnhandledOptionException(Exception):
pass

# Then, later on...

raise UnhandledOptionException("-q")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Wanderer
On Jul 24, 4:31 pm, Ian Kelly  wrote:
> On Tue, Jul 24, 2012 at 1:57 PM, Wanderer  wrote:
> > If I use the code
>
> > assert False, "unhandled option"
>
> > I get output like:
>
> > option -q not recognized
> > for help use --help
>
> > What other expressions can I use other than "unhandled option"? Is there a 
> > list somewhere?
>
> Are you using argparse or optparse or getopt or something else
> altogether?  And where are you placing this assert?  It would be
> helpful to see some actual code to understand what you are doing.
>
> And by the way, assert is a very bad way to check user input or to
> unconditionally raise an exception.  The reason is that if Python is
> invoked with -O, then all assertions are removed from the compiled
> bytecode, and then your unconditional exception code doesn't raise any
> exception at all.  If you want to raise an exception, just do it:
>
> raise Exception("unhandled option")
>
> Ideally, you would also subclass Exception to create a more specific
> exception class for your custom exception:
>
> class UnhandledOptionException(Exception):
>     pass
>
> # Then, later on...
>
> raise UnhandledOptionException("-q")

I left out the Usage class

class Usage(Exception):
def __init__(self, msg):
self.msg = msg

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Wanderer
On Jul 24, 4:47 pm, Wanderer  wrote:
> On Jul 24, 4:31 pm, Ian Kelly  wrote:
>
>
>
>
>
>
>
>
>
> > On Tue, Jul 24, 2012 at 1:57 PM, Wanderer  wrote:
> > > If I use the code
>
> > > assert False, "unhandled option"
>
> > > I get output like:
>
> > > option -q not recognized
> > > for help use --help
>
> > > What other expressions can I use other than "unhandled option"? Is there 
> > > a list somewhere?
>
> > Are you using argparse or optparse or getopt or something else
> > altogether?  And where are you placing this assert?  It would be
> > helpful to see some actual code to understand what you are doing.
>
> > And by the way, assert is a very bad way to check user input or to
> > unconditionally raise an exception.  The reason is that if Python is
> > invoked with -O, then all assertions are removed from the compiled
> > bytecode, and then your unconditional exception code doesn't raise any
> > exception at all.  If you want to raise an exception, just do it:
>
> > raise Exception("unhandled option")
>
> > Ideally, you would also subclass Exception to create a more specific
> > exception class for your custom exception:
>
> > class UnhandledOptionException(Exception):
> >     pass
>
> > # Then, later on...
>
> > raise UnhandledOptionException("-q")
>
> I left out the Usage class
>
> class Usage(Exception):
>     def __init__(self, msg):
>         self.msg = msg

I seem to be missing a post.

Here is the code.

class Usage(Exception):
def __init__(self, msg):
self.msg = msg

def main(argv=None):

help_message = \
("\nOtFixture.py:\n Set the Optics Test Fixture Light Source Light
Level\n" +
 "Options:\n"
 "  -l, --level= \n"
+
 "  -v, --verbose: Print messages to the terminal.\n"
 "  -h, --help: This message\n")

level = None
verbose = False
helpflag = False

options = "hl:v"
long_options = ["help","level=","verbose"]
if argv is None:
argv = sys.argv
try:
try:
opts, _args = getopt.getopt(argv[1:],
options,long_options)
except getopt.error, msg:
raise Usage(msg)

for o, a in opts:
if o in ("-h", "--help"):
print help_message
helpflag = True
elif o in ("-l", "--level"):
level = a
elif o in ("-v", "--verbose"):
verbose = True
else:
assert False, "unhandled option"

if not helpflag:
if level == None:
level = raw_input("Enter the light level from 0.0 to
100.0%: ")
if level.replace(".", "", 1).isdigit():
level = float(level)
else:
msg = "\n" + str(level) + " is not a number.\n"
raise Usage(msg)

if verbose and level is not None:
print "The level is ", level, " percent"

if level is not None:
if 0.0 <= level <= 100.0:
ot = OtFixture(verbose)
ot.setLightLevel(level)
print "Light Level set to ", level,"%."
else:
msg = "\n" + str(level) + " is not in the range 0.0 to
100.0%\n"
raise Usage(msg)


except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2

if __name__ == "__main__":
sys.exit(main())

I don't really have a problem. I'm was just curious.

How do you invoke python -O? When I run python.exe -O OtFixture.py -q,
I get the same response. It's a capital letter O, right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Wanderer
On Jul 24, 4:31 pm, Ian Kelly  wrote:
> On Tue, Jul 24, 2012 at 1:57 PM, Wanderer  wrote:
> > If I use the code
>
> > assert False, "unhandled option"
>
> > I get output like:
>
> > option -q not recognized
> > for help use --help
>
> > What other expressions can I use other than "unhandled option"? Is there a 
> > list somewhere?
>
> Are you using argparse or optparse or getopt or something else
> altogether?  And where are you placing this assert?  It would be
> helpful to see some actual code to understand what you are doing.
>
> And by the way, assert is a very bad way to check user input or to
> unconditionally raise an exception.  The reason is that if Python is
> invoked with -O, then all assertions are removed from the compiled
> bytecode, and then your unconditional exception code doesn't raise any
> exception at all.  If you want to raise an exception, just do it:
>
> raise Exception("unhandled option")
>
> Ideally, you would also subclass Exception to create a more specific
> exception class for your custom exception:
>
> class UnhandledOptionException(Exception):
>     pass
>
> # Then, later on...
>
> raise UnhandledOptionException("-q")

I'm using getopt but not at that point. I really don't have a problem.
I'm just curious. I've never seen anything else after
assert False,

Here is some code.

def main(argv=None):

help_message = \
("\nOtFixture.py:\n Set the Optics Test Fixture Light Source Light
Level\n" +
 "Options:\n"
 "  -l, --level= \n"
+
 "  -v, --verbose: Print messages to the terminal.\n"
 "  -h, --help: This message\n")

level = None
verbose = False
helpflag = False

options = "hl:v"
long_options = ["help","level=","verbose"]
if argv is None:
argv = sys.argv
try:
try:
opts, _args = getopt.getopt(argv[1:],
options,long_options)
except getopt.error, msg:
raise Usage(msg)

for o, a in opts:
if o in ("-h", "--help"):
print help_message
helpflag = True
elif o in ("-l", "--level"):
level = a
elif o in ("-v", "--verbose"):
verbose = True
else:
assert False, "unhandled option"

if not helpflag:
if level == None:
level = raw_input("Enter the light level from 0.0 to
100.0%: ")
if level.replace(".", "", 1).isdigit():
level = float(level)
else:
msg = "\n" + str(level) + " is not a number.\n"
raise Usage(msg)

if verbose and level is not None:
print "The level is ", level, " percent"

if level is not None:
if 0.0 <= level <= 100.0:
ot = OtFixture(verbose)
ot.setLightLevel(level)
print "Light Level set to ", level,"%."
else:
msg = "\n" + str(level) + " is not in the range 0.0 to
100.0%\n"
raise Usage(msg)


except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2

if __name__ == "__main__":
sys.exit(main())



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 2:44 PM, Wanderer  wrote:
> I'm using getopt but not at that point. I really don't have a problem.
> I'm just curious. I've never seen anything else after
> assert False,
>
> Here is some code.

It doesn't matter what you put after the assert False, because that
line is not actually reached.  When getopt sees the -q, it immediately
raises a getopt.error, which you catch and then immediately reraise as
a Usage exception, which is then caught and printed at the end.  The
chained ifs with the assert statement never even execute in this
scenario.

Seeing the assert in context, it makes more sense.  It's not
intercepting some unimplemented option and preventing the program from
proceeding; it's there as a development tool to catch programming
errors where an option is added to the getopt configuration but is not
implemented in the if chain.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Wanderer
On Jul 24, 5:22 pm, Ian Kelly  wrote:
> On Tue, Jul 24, 2012 at 2:44 PM, Wanderer  wrote:
> > I'm using getopt but not at that point. I really don't have a problem.
> > I'm just curious. I've never seen anything else after
> > assert False,
>
> > Here is some code.
>
> It doesn't matter what you put after the assert False, because that
> line is not actually reached.  When getopt sees the -q, it immediately
> raises a getopt.error, which you catch and then immediately reraise as
> a Usage exception, which is then caught and printed at the end.  The
> chained ifs with the assert statement never even execute in this
> scenario.
>
> Seeing the assert in context, it makes more sense.  It's not
> intercepting some unimplemented option and preventing the program from
> proceeding; it's there as a development tool to catch programming
> errors where an option is added to the getopt configuration but is not
> implemented in the if chain.

Thanks. Now it makes more sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python packaging tools to maintain source distributions in other languages?

2012-07-24 Thread eric . lemings
On Monday, July 23, 2012 11:59:10 PM UTC-6, Rusi wrote:
> On Jul 23, 11:16 pm, eric.lemi...@gmail.com wrote:
> > Greetings all,
> >
> > I would like to leverage the Python packaging tools (e.g. distutils, 
> setuptools, distribute, et. al.) to maintain (i.e. download, extract, 
> configure, make, install, package) source distributions other than Python 
> modules (e.g. zlib, openssl).
> >
> > Are there any open-source packages/tools that already do this?  Any 
> documentation in print or on the web that outlines a basic plan for doing 
> such?
> >
> > Any and all help greatly appreciated.
> 
> Ive heard good things about scons
> http://en.wikipedia.org/wiki/SCons

I've heard about SCons but don't know much about it.  From what little I've 
read, it's only a make tool replacement.  I'm looking for more "end-to-end" 
maintenance tools similar to -- perhaps built upon -- disutils, setuptools, and 
company.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto do a robust simple cross platform beep

2012-07-24 Thread Gelonida N
On 07/15/2012 03:15 AM, rantingrickjohn...@gmail.com wrote:> On Friday, 
July 13, 2012 8:00:05 PM UTC-5, gelonida wrote:

>> I just want to use a beep command that works cross platform. [...] I
>> just want to use them as alert, when certain events occur within a
>> very long running non GUI application.
>
> I can see a need for this when facing a non GUI interface.
That's exactly my usecase.
A rather tiny script running for hours and telling the users when 
results are ready.


But even "IF" you do manage to play a sound in a cross platform manner; 
if the speaker volume is too low, or the speakers are turned off, or the 
computer does not have speakers connected, etc... your user will never 
hear the alert! In this case, beeping the built-in speaker has the 
fail-safe advantage.

>

Well the user starts the script, because he wants to get immediate 
notification while being able mimimize the window, work on a different a 
machine or doing some paperwork or discussions.

So it would be up to him to configure the volume appropraitely.

> Why not wrap up the functionality and release a module yourself? If 
you are not sure how to access the speaker on one or more OSs then ask 
on the list. I would love to see some community effort behind this.

>

I'm having no some ugly code, that is working on the platforms, that I 
am using.



I'm rather busy, and have no experience in publishing coe, that's good 
enough for the community.



I could try to use this a test case for learning to create communicty 
modules.


Is there any decent getting started guide.

Could I use github (as O know git already)?

Assuming, the module would achieve a state, where it could be usable by 
others. How would one register on Pypi?


> PS: Better make sure this module does not exist though ;-)
>

I didn't find one, that's why I asked here.


--
http://mail.python.org/mailman/listinfo/python-list


Re: howto do a robust simple cross platform beep

2012-07-24 Thread Chris Angelico
On Wed, Jul 25, 2012 at 7:39 AM, Gelonida N  wrote:
> On 07/15/2012 03:15 AM, rantingrickjohn...@gmail.com wrote:> On Friday, July
> 13, 2012 8:00:05 PM UTC-5, gelonida wrote:
>>> I just want to use a beep command that works cross platform. [...] I
>>> just want to use them as alert, when certain events occur within a
>>> very long running non GUI application.
>>
>> I can see a need for this when facing a non GUI interface.
> That's exactly my usecase.
> A rather tiny script running for hours and telling the users when results
> are ready.

Sounds reasonable. I'd be inclined to solve just my own problem,
though; work it out for the platforms you use, and don't worry too
much about the rest. But that's because I'm lazy :)

> Could I use github (as O know git already)?

You certainly could, though that doesn't help with the whole "building
a module" part. (And I can't help there either, never done it. Sorry.)

There are quite a few ways of creating an alert such as you describe.
The easiest way may be to play a .WAV file rather than a system beep;
there are a number of different options on different platforms, so
your module could be written in pure Python and basically wrap the
whole lot up into a huge bunch of "except ImportError" checks. Here's
a few ways:

http://stackoverflow.com/questions/307305/play-a-sound-with-python

Burying all that complexity behind a simple "play_sound()" function
would be handy, and you could easily start with just 2-3 options and
add more later.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


[OT] git and hg in prompt (was: My first ever Python program, comments welcome)

2012-07-24 Thread Tim Delaney
On 24 July 2012 21:34, Lipska the Kat  wrote:

> On 24/07/12 06:13, rusi wrote:
>
>> On Jul 22, 10:23 pm, Lipska the Kat  wrote:
>>
>>  Heh heh, Nothing to do with Eclipse, just another thing to get my head
>>> around. For work and Java IMHO you can't beat eclipse...
>>> at the moment I'm getting my head around git,
>>>
>>
>> Bumped into this yesterday. Seems like a good aid to git-comprehension
>> https://github.com/git/git/**blob/master/contrib/**
>> completion/git-prompt.sh
>>
>
> eek ... now that's a shell script to be proud of isn't it .. and it works
> [lipska@ubuntu fileio (master)]$ impressive. Good find, thanks.


OT, but I have the following in my prompt covering both git and hg - much
simpler, but gives similar information. Extending should be fairly easy.

function hg_ps1() {
# requires http://stevelosh.com/projects/hg-prompt/
#hg prompt '[{update}{{tags|:}:}{{bookmark}:}{branch}:{rev}] ' 2>
/dev/null
hg prompt '[{update}{branch}:{rev}] ' 2> /dev/null
}

function git_ps1() {
local head="`git rev-list -n 1 --abbrev-commit HEAD 2> /dev/null`"

if [ "${head}" != "" ] ; then
local branch="`git branch --no-color 2> /dev/null | sed -e
'/^[^*]/d' -e 's/* \(.*\)/\1/'`"

# Puts a ^ in the prompt if this revision is not FETCH_HEAD
local uptodate="`git log --no-color -n 1 --pretty=format:^
HEAD..FETCH_HEAD 2> /dev/null`"

# Puts a comparison with the remote tracking branch in the prompt:
+ (ahead), - (behind) or * (both - diverged).
local tracking="`git branch -avv --no-color 2> /dev/null | sed -e
'/^[^*]/d' -e 's/  */ /g' -e 's/* \(.*\)/\1/' -e
's/^[^[]*\[\([^]]*\)\].*$/\1/' -e 's/^.*ahead [0-9][0-9]*/+/' -e
's/[^+].*behind [0-9][0-9]*.*$/-/' -e '/^[^+-]/d' -e 's/+-/*/'`"

echo "[${tracking}${uptodate}${branch}:${head}] "
return 0
fi

return 1
}

function git_hg_ps1() {
git_ps1

if [ $? -eq 0 ] ; then
return 0
fi

hg_ps1
return $?
}

export 
PS1='$(git_hg_ps1)\[\033[1;30m\]${USERNAME}@${HOSTNAME}:\[\033[0m\]\[\033[1;30m\]${PWD%%${PWD##$HOME}}\[\033[0m\]${PWD##$HOME}>
'

It's designed to call as few external processes as possible (esp. when not
in a git repository) since it's used on Windows as well (msys, should work
in cygwin) and spawning on Windows is slow.

Tim Delaney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto do a robust simple cross platform beep

2012-07-24 Thread Jerry Hill
On Fri, Jul 13, 2012 at 9:00 PM, Gelonida N  wrote:
> I tried the simplest approach (just printing the BEL character '\a' chr(7)
> to the console.

That's what I do when I want to send an audible alert to the user of a
console based program.  It's then up to the user's terminal to do
whatever the user wants. Printing a BEL character has the added
advantage that it plays nicely with programs that are run remotely
(through ssh sessions and the like).

Personally, I'm usually in a screen session, inside either an xterm or
over an ssh link, and have visual bells turned on so I can see the
alerts, even when they pop up in another screen.

-- 
Jerry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto do a robust simple cross platform beep

2012-07-24 Thread Dan Stromberg
On Sat, Jul 14, 2012 at 1:00 AM, Gelonida N  wrote:

>
> What I do at the moment is:
>
> For Windows I use winsound.Beep
>
> For Linux I create some raw data and pipe it into sox's
> 'play' command.
>
> I don't consider this very elegant


You may want to get over that.  Some software vendors/distributors don't
want you to be able to do things portably.  Others have "not invented here"
syndrome.  A lot of programming is adding multiple ways of doing the same
thing to program around the stupid wars ("choices") the vendors and
distributors push on us.

Or if you're really an idealist, start your own project to abstract away
these silly details.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python packaging tools to maintain source distributions in other languages?

2012-07-24 Thread Rusi
On Jul 25, 2:25 am, eric.lemi...@gmail.com wrote:
> On Monday, July 23, 2012 11:59:10 PM UTC-6, Rusi wrote:
> > Ive heard good things about scons http://en.wikipedia.org/wiki/SCons
>
> I've heard about SCons but don't know much about it.  From what little I've 
> read, it's
> only a make tool replacement.  I'm looking for more "end-to-end" maintenance 
> tools similar to --
> perhaps built upon -- disutils, setuptools, and company.

Maybe try the relevant lists/fora like the foll?

http://groups.google.com/group/packaging-guide/about
http://mail.python.org/mailman/listinfo/distutils-sig
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ben Finney
Maarten  writes:

> You just missed it:
> 22/7

Which is appropriate, since 22/7 misses π by a wide margin. (355/113 is
my favourite approximation to π, and is far more accurate.)

−1 on associating 22/7 as anything to do with π.

+1 on celebrating τ day! https://www.youtube.com/watch?v=jG7vhMMXagQ>

-- 
 \ “Why am I an atheist? I ask you: Why is anybody not an atheist? |
  `\  Everyone starts out being an atheist.” —Andy Rooney, _Boston |
_o__)Globe_ 1982-05-30 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Chris Angelico
On Wed, Jul 25, 2012 at 1:07 PM, Ben Finney  wrote:
> Which is appropriate, since 22/7 misses π by a wide margin. (355/113 is
> my favourite approximation to π, and is far more accurate.)

22/7 is no worse than 3.14, though. Sure, 355/113 is closer still, but
how often do really need more accuracy than 22/7? 3.142857 vs 3.141593
- it's 0.04% out, versus 3.14 which is 0.05% out.

Anyway, 355/113 makes a really awkward date to celebrate. :)

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Steven D'Aprano
On Wed, 25 Jul 2012 13:07:03 +1000, Ben Finney wrote:

> Maarten  writes:
> 
>> You just missed it:
>> 22/7
> 
> Which is appropriate, since 22/7 misses π by a wide margin. (355/113 is
> my favourite approximation to π, and is far more accurate.)

Approximation? Pffft. I use the exact value:

π = 16*arctan(1/5) - 4*arctan(1/239)


For those lacking ambition, another approximation is:

π ≈ 9801 ÷ (2206*√2)

Other interesting approximations are:

π ≈ 9/5 + √(9/5)

π ≈ √√(2143/22)

See more here:

http://mathworld.wolfram.com/PiFormulas.html
http://mathworld.wolfram.com/PiApproximations.html

 
> −1 on associating 22/7 as anything to do with π.

I believe that 22/7 is the closest approximation to π with a denominator 
under 100. It is the second convergent of the continued fraction:

π = [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...]

which means that, like it or not, 22/7 *is* associated with π.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 StreamReader.readline()

2012-07-24 Thread Ulrich Eckhardt

Am 24.07.2012 17:01, schrieb cpppw...@gmail.com:

 reader = codecs.getreader(encoding)
 lines  =  []
 with open(filename, 'rb') as f:
 lines  = reader(f, 'strict').readlines(keepends=False)

where encoding == 'utf-16-be'
Everything works fine, except that lines[0] is equal to codecs.BOM_UTF16_BE
Is this behaviour correct, that the BOM is still present?


Yes, assuming the first line only contains that BOM. Technically it's a 
space character, and why should those be removed?


Uli
--
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Mark Lawrence

On 25/07/2012 07:07, Steven D'Aprano wrote:

On Wed, 25 Jul 2012 13:07:03 +1000, Ben Finney wrote:


Maarten  writes:


You just missed it:
22/7


Which is appropriate, since 22/7 misses π by a wide margin. (355/113 is
my favourite approximation to π, and is far more accurate.)


Approximation? Pffft. I use the exact value:

π = 16*arctan(1/5) - 4*arctan(1/239)


For those lacking ambition, another approximation is:

π ≈ 9801 ÷ (2206*√2)

Other interesting approximations are:

π ≈ 9/5 + √(9/5)

π ≈ √√(2143/22)

See more here:

http://mathworld.wolfram.com/PiFormulas.html
http://mathworld.wolfram.com/PiApproximations.html



−1 on associating 22/7 as anything to do with π.


I believe that 22/7 is the closest approximation to π with a denominator
under 100. It is the second convergent of the continued fraction:

π = [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...]

which means that, like it or not, 22/7 *is* associated with π.





Any civil engineers reading this who would find 22/7 perfectly adequate 
for their task?


--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ben Finney
Mark Lawrence  writes:

> Any civil engineers reading this who would find 22/7 perfectly
> adequate for their task?

Civil engineering? Pffft, that deals with only a few orders of magnitude
range at most. “π is roughly 3” is usually good enough in that arena :-)

-- 
 \ “You don't need a book of any description to help you have some |
  `\kind of moral awareness.” —Dr. Francesca Stavrakoloulou, bible |
_o__)  scholar, 2011-05-08 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list