Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-05 Thread Rustom Mody
On Saturday, April 5, 2014 11:27:08 AM UTC+5:30, Chris Angelico wrote:
> On Sat, Apr 5, 2014 at 4:29 PM, Ben Finney wrote:
> > Without actual data - which neither of us has on this matter - all of
> > these hypotheses are unfounded speculation. Let's not draw any
> > conclusions in the absence of evidence.
> 
> Not to mention that there's not a lot of difference between an
> unemployed professional coder and a serious hobbyist. :)

Since I started this distinction, I would like to clarify that I dont take it
too seriously.
My impressions:
1. The number of people who read (lurk (on GG!!)) is significantly higher than 
those who post. 3 times? 10 times? Dunno

2. And they fall into an in-between limbo region: ie students -- some formal, 
some informal -- who would like to become python 'professionals' but
dont see themselves as that right now

And in case you missed it, I was suggesting that the idea that python 2
support should be cavalierly dropped implied a completely hobbyist viewpoint.

Professionalism implies at bottom that a client is God even if
he is being an asshole.  Intel, Microsoft, IBM and any successful brick-n-mortar
corp of your choice, will be seen to follow this principle scrupulously
Of course you are free to prefer the '90%'
[Run your favorite search engine on "90 percent of startups..."

Of course that does not mean that I find the 'conservatism' of python's choices 
happy.
Here is a recent thread 
https://mail.python.org/pipermail/python-list/2014-February/667169.html
and its contained link http://bugs.python.org/issue2506
I am too far removed from the details to comment on the technical merit of it
However reading it suggests that decisions are being made on 
"conservatism is good, change is not" basis
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-05 Thread Chris Angelico
On Sat, Apr 5, 2014 at 5:48 PM, Mark H Harris  wrote:
> On 4/5/14 1:01 AM, Ben Finney wrote:
>>
>> Mark H Harris  writes:
>>
>>> On 4/5/14 12:02 AM, Ian Kelly wrote:

 A fork is undesirable because it fragments the community.  I don't
 think "fear" or "panic" are the right words for it.
>>>
>>>
>>> Yes. I get that.
>>
>>
>> So, you get that “fear” and “panic” are not the right words to
>> characterise the undesirability Ian describes.
>
>
>Not so much. I 'get' his point about community fragmentation. I disagree
> that 'fear' is not the correct word. Its semantics, really, but the root is
> 'fear' of community fragmentation. This is something less than 'fear' as in
> terror, or fear as in irrational, or fear as in childish (or something like
> that).

In that case, don't quote both sentences and say "I get that", because
people will interpret that to mean that you "get" both of them. You do
have the power to edit quoted text and insert your responses in the
exact right places.

>Often decisions are made within tension (fear) that the price of
> consequences will not warrant the effort, nor heroism. I believe that
> decisions should be made because "its the right thing to do," and not
> because, "if we force this too soon there will be a fork," kinda thing.
> Decision out of fear is not good. Conservative posturing within tension
> might be good, as long as its not carried out too far.

I avoid stepping out onto the road in front of a truck, out of fear
that the truck will hit me and break the screen on my laptop. (And
secondarily, because getting hit will hurt. Priorities.) Is that a bad
decision? At what point does something stop being "conservative
posturing" or sane decision-making and start being a "decision out of
fear"?

>I personally want python 3.3+ on my android devices. Well, QPython is
> stuck on 2.7.2 because why? Twisted does not fully work on 3.x yet. What's
> the solution? Get Twisted up to speed. (gevent is similar).
>Now, I don't think QPython will want to maintain a fork. I also don't
> think they will want to stay on 2.7.2 forever, because they will want
> security patches. They will eventually get up to speed when Twisted is
> ready. What I wish the C python community would do is to apply just a little
> pressure here so that the Twisted community is motivated to move a little
> faster.  This is taking too long, and yes, I think the core devs are afraid
> of offending (or fragmenting) constituents.  I might be wrong.

Why 2.7.2? That can't be because of Twisted. There must be some other
reason for not upgrading within 2.7.

>Very seldom is anything black & white. Always we entertain shades of grey
> and a panacea of color and multiple hues.

(You may mean a "rainbow" of color or something, but not a "panacea",
which is a quite different thing. According to the Baroness von
Krakenfeldt, old wine is a panacea - as long as someone else pays the
bill.)

And yet ultimately, many things *are* black and white. There is truth,
and there is falsehood. Something may be accurate to a greater or
lesser degree (if I say that the human body is "mostly" water, then
I'm correct; if I say the human body is "about 60% water" then I'm
more correct, but if I say the human body is "95.2423% water", then
I'm flat out wrong), but correctness is absolute. It's impossible to
conduct a sane debate if those participating do not at least attempt
to maintain a position, and acknowledge when that position changes.
There's nothing wrong with shifting, if done graciously and without
trying to pretend that you haven't shifted. (After all, that's usually
the point of a debate - to have two extreme positions progressively
clarified and shifted until they come into agreement.)

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-05 Thread Chris Angelico
On Sat, Apr 5, 2014 at 5:59 PM, Rustom Mody  wrote:
> Professionalism implies at bottom that a client is God even if
> he is being an asshole.

Not really :) Sometimes, your employer or client just has to go jump.
Professionalism implies that you treat your client at least as well as
s/he deserves, and try to solve his/her problems. If that becomes
impractical, your client can find a new Charlie. :)

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


Python streaming media server

2014-04-05 Thread Wesley
Hi,
  Anyone knows open source streaming media server written by Python?

I am trying to setup a streaming media server in python, wanna find an existing 
one and have a look.

Thanks.
Wesley
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-05 Thread Steven D'Aprano
On Sat, 05 Apr 2014 00:02:58 -0500, Mark H Harris wrote:

> Having said that, I do believe that the migration to C python3 has
> been too conservative. 

Why? Is it a race? Does Python 2.x turn into PHP at midnight?

Some people think the move to Python 3 has been too radical and too fast 
for them. Are they wrong?


> Nobody wants to maintain a fork, not really.

There will be no serious fork of Python 2.7.

Oh, I dare say that when the core developers finally announce Python 2.7 
is end-of-lifed, probably in another five or so years, there will be a 
flurry of cheap talk about forking Python, and maybe even a few 
"Python2.8" projects on Github. But nobody will use them, and they will 
fade away into obscurity. I can't see *anyone* with the necessary  
resources taking on the job and gathering enough community support for a 
successful fork.

With perhaps one exception. Twisted has apparently said they cannot 
migrate to 3.x. They might, I suppose, take up maintenance of Python 2.7. 
But I doubt it. I expect that when push comes to shove in 4 or 5 years 
time, they'll find a way to migrate.

Python 2.7 will continue to get paid-for support from RedHat until 2024, 
and I expect that there will be companies like Activestate that will 
offer extended support for Python 2.7 for a few years too. But that's it.


> I don't think its something anyone should be afraid of.

Nobody is *afraid* of a fork. But forks do split the community, and 
introduce FUD (Fear, Uncertainty, Doubt), except for the rare occasions 
like the XFree86 to X.Org fork where the entire community moved almost 
overnight to the fork. That was a HUGE vote of no confidence to the 
original maintainer, and (so I'm told) deservedly so.

Nothing like that is plausible with Python. There simply isn't anywhere 
near that level of dissatisfaction with the way the language is being 
managed, mild grumbling from a few people aside. Most importantly, the 
core devs have been *very* responsive to people's complaints.


> Somebody should
> put a date on C python 3.4+ migration and cut off support for 2.7.x/

2045-04-01. If you're not migrated to Python 3.4 by then, no cake for you.

A date will be set when the time is right, but rushing to set a date now 
when we don't know the state of the language in five years time is just 
silly. It is expected to be five years from now, but if there is a flurry 
of migration activity it may be brought forward, and if five years is not 
long enough it may be delayed. *May* be delayed. 

It's fine if people don't migrate to 3.4. Waiting until 3.5 or even 3.6 
is perfectly acceptable too. Leaving it to 3.7 (expected about 5 years 
from now) is probably okay too. The longer you wait to migrate, the 
easier it will be: migrate when the benefit of migrating exceeds the cost.

(I'm talking about application-level projects here. Libraries and 
frameworks are somewhat different.)

Each point release of 3.x has added not just new features to entice 
users, but new features (and sometimes old features) to aid in porting. 
For example, some things that had been dropped, like the callable() built-
in, were re-added in 3.2. 3.3 re-added the u'' syntax solely to aid in 
porting from 2.x. There is a lot of discussion going on to make it easier 
to deal with mixed bytes and ASCII text, which is a very important use-
case which by accident was suited well to the Python 2.x byte-string 
model, but not well suited to the Python 3.x unicode-text versus bytes 
model. You should expect that to come into production in 3.5.


> Its
> just an opinion. If 'Twisted' isn't ready for 3.x, well, they need to
> get ready. 


Are you volunteering to do the work for them?


> That's also just an opinion.

Ah, but is it an *informed* opinion? Do you know why Twisted say they 
cannot migrate to 3.x?




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-05 Thread Terry Reedy

On 4/5/2014 6:19 AM, Steven D'Aprano wrote:


Oh, I dare say that when the core developers finally announce Python 2.7
is end-of-lifed, probably in another five or so years,


Bug fixing will end in May/June 2015 with 2.7.8, maybe 2.7.9. It will 
probably start tapering off before that on the basis that fixes may 
break working code that has worked around bugs. I am not sure how long I 
will backport Idle patches.


Code-only security patches after that? Undecided. I think PEP 466 
defines what the focus will be -- keeping 2.7 web apps from becoming bad 
internet citizens.


--
Terry Jan Reedy

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-05 Thread Roy Smith
In article <533fd894$0$29993$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> Twisted has apparently said they cannot migrate to 3.x. They might, I 
> suppose, take up maintenance of Python 2.7. But I doubt it. I expect 
> that when push comes to shove in 4 or 5 years time, they'll find a 
> way to migrate.

Is Twisted really that relevant?  I know they've been around for a long 
time, and there are a few high-profile projects using them, but I get 
the impression they've become a bit of a legacy product by now, and 5 
years from now, I suspect that will be even more true.

Their big claim to fame was the ability to do asynchronous I/O in 
Python.  There's other ways to do that now.

> Nobody is *afraid* of a fork. But forks do split the community, and 
> introduce FUD 

A classic example would be the BSD world (Free, Net, Open, Dragonfly, 
and a host of minor players).  There's a lot of really smart people 
working on those projects, but they're all pushing in different 
directions.  Meanwhile, Linux ate their lunch.

>> Somebody should
>> put a date on C python 3.4+ migration and cut off support for 2.7.x/
> 
> 2045-04-01. If you're not migrated to Python 3.4 by then, no cake for you.

But, somewhere, somebody will still be running XP on their desktop, and 
haggling with Microsoft over another deadline extension.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python streaming media server

2014-04-05 Thread Sturla Molden
Wesley  wrote:

>   Anyone knows open source streaming media server written by Python?
> 
> I am trying to setup a streaming media server in python, wanna find an
> existing one and have a look.

Not open source, but there is a famous closed-source one called YouTube.

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


Re: Two Questions about Python on Windows

2014-04-05 Thread Tim Roberts
maxerick...@gmail.com wrote:
>
>You can also edit the PATHEXT environment variable to include .py/.pyw,
>making the python source files executable (as long as the types are 
>properly registered with Windows; if double clicking runs them they
>should be properly registered).

Let me clarify that just a bit.

There are several ways to run Python scripts from a Windows command line.
You can invoke the interpreter specifically by name:
C:\Apps\Python27\python xxx.py
C:\Apps\Python27\python xxx.pyw

Or, if the Python directory is in your path:
python xxx.py
python xxx.pyw

If the .py and .pyw extension are registered using assoc and ftype (which
the Windows installer does), then you can invoke them by file name:
xxx.py
xxx.pyw

If you add those extensions to PATHEXT, then you do not even need to
provide the extension, so they will look just like any other automatically
executable program:
xxx
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python streaming media server

2014-04-05 Thread Wesley
在 2014年4月6日星期日UTC+8上午1时38分57秒,Sturla Molden写道:
> Wesley  wrote:
> 
> 
> 
> >   Anyone knows open source streaming media server written by Python?
> 
> > 
> 
> > I am trying to setup a streaming media server in python, wanna find an
> 
> > existing one and have a look.
> 
> 
> 
> Not open source, but there is a famous closed-source one called YouTube.

Are you kidding?
I know youtube, but do you think we can use it setup our own streaming media 
server?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python streaming media server

2014-04-05 Thread Steven D'Aprano
On Sat, 05 Apr 2014 18:51:58 -0700, Wesley wrote:

> 在 2014年4月6日星期日UTC+8上午1时38分57秒,Sturla Molden写道:
>> Wesley  wrote:
>> 
>> >   Anyone knows open source streaming media server written by Python?
>> > 
>> > I am trying to setup a streaming media server in python, wanna find
>> > an existing one and have a look.
>> 
>> 
>> Not open source, but there is a famous closed-source one called
>> YouTube.
> 
> Are you kidding?
> I know youtube, but do you think we can use it setup our own streaming
> media server?

I'm sure if you have a few hundreds of million dollars, you could buy 
YouTube from Google. Otherwise, no. It is secret, proprietary software, 
not available to anyone else.

Speaking of Google, did you try this?

https://www.google.com.au/search?q=python+streaming+video

Does that help?

Unfortunately, Google customizes the search results depending on who you 
are and where you are, so you may not see what I see. But for me, the top 
link (after the paid ads) is for a Python video streaming server.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python streaming media server

2014-04-05 Thread Ben Finney
Steven D'Aprano  writes:

> Unfortunately, Google customizes the search results depending on who you 
> are and where you are, so you may not see what I see.

Which is one of many reasons to prefer a search engine that doesn't put
you in a search bubble like that.

DuckDuckGo returns search results impartially because they don't track
your search results:

   https://duckduckgo.com/?q=python+"streaming+media"+server>

-- 
 \   “I don't care to belong to a club that accepts people like me |
  `\as members.” —Groucho Marx |
_o__)  |
Ben Finney

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


How can I parse this correctly?

2014-04-05 Thread Anthony Papillion
Hello Everyone,

I'm working with historical earthquake data and I have a tab delimited
file. I'm using the csv module with the \t delimiter to denote it's
tab separated and it's working fine. I've set things up loike this:

import csv

f = open('earthquakes.tsv')
r = csv.DictReader(f, delimiter='\t')

for row in r:
print row['YEAR']

This works fine. But, I am needing to do date addition/subtraction
using datetime and so I need these dates as integers. When I try to
cast them like this:

print int(row['YEAR'])

I am told by the interpreter:

Traceback (most recent call last):
  File "analyze.py", line 14, in 
print int(row['MONTH'])
ValueError: invalid literal for int() with base 10: ''

What am I doing wrong? Am I not understanding HOW to cast?

Thanks,
Anthony
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I parse this correctly?

2014-04-05 Thread Chris Angelico
On Sun, Apr 6, 2014 at 1:52 PM, Anthony Papillion  wrote:
> When I try to
> cast them like this:
>
> print int(row['YEAR'])
>
> I am told by the interpreter:
>
> Traceback (most recent call last):
>   File "analyze.py", line 14, in 
> print int(row['MONTH'])
> ValueError: invalid literal for int() with base 10: ''
>
> What am I doing wrong? Am I not understanding HOW to cast?

An empty string isn't a valid Python integer, unlike in some other
languages where it's taken as zero. Do you have data in some but not
in others? Should all blank entries be interpreted as zero? (That's
common with a lot of spreadsheets.) Make sure that's really what you
want, and then just do this:

print int(row['MONTH'] or 0)

That'll set a default of zero, if (and only if) the MONTH string is blank.

By the way, is there a reason you're using Python 2 rather than Python
3? For new projects, you ideally should be working with a more recent
version of Python; that way, you won't have to edit your code later,
when you find there's some newer feature that you want. The
differences aren't huge, but the sooner you make the change, the less
code you have to look at.

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


Re: How can I parse this correctly?

2014-04-05 Thread Ben Finney
Anthony Papillion  writes:

> for row in r:
> print row['YEAR']
>
> This works fine. But, I am needing to do date addition/subtraction
> using datetime and so I need these dates as integers.

I assume you mean you will be creating ‘datetime.date’ objects. What
will you set as the month and day?

Alternatively, if you just want to do integer arithmetic on the year,
you don't need the ‘datetime’ module at all.

> When I try to cast them like this:

Python doesn't have “cast”; instead, you request the creation of a new
object by calling the type.

> print int(row['YEAR'])

What do you expect this to return when ‘row['YEAR']’ is ‘""’ (empty
string)?

> I am told by the interpreter:
>
> Traceback (most recent call last):
>   File "analyze.py", line 14, in 
> print int(row['MONTH'])
> ValueError: invalid literal for int() with base 10: ''
>
> What am I doing wrong?

You've ignored the condition where your ‘row['YEAR']’ is the empty
string. Python doesn't have an unambiguous integer represented by the
empty string, so it refuses to guess.

You'll need to handle that specially, and decide what value you want
when that's the case.

-- 
 \“A free press is one where it's okay to state the conclusion |
  `\  you're led to by the evidence.” —Bill Moyers |
_o__)  |
Ben Finney

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


Re: Python streaming media server

2014-04-05 Thread Wesley
在 2014年4月5日星期六UTC+8下午6时11分02秒,Wesley写道:
> Hi,
> 
>   Anyone knows open source streaming media server written by Python?
> 
> 
> 
> I am trying to setup a streaming media server in python, wanna find an 
> existing one and have a look.
> 
> 
> 
> Thanks.
> 
> Wesley

After a lot google work, I am looking at Flumotion.
Need to check the streaming mode and file formats it support.

Wesley
-- 
https://mail.python.org/mailman/listinfo/python-list


If statement issue driving me nuts

2014-04-05 Thread Anthony Smith
Hi

I have a small project and I have been unable to get the following statement to 
work. Any help would great.
User inputs can either self_sale_head which is a $ value,if a $ value is not 
add a self.estimated_weight_hd is used to get the total weight, 
the code below should return a estimated_weight_total which can be used for the 
total sale price. 
All works when I add the estimated_weight_total manually. I am lost as why.

def calc_estimated_weight_total(self):
if self.sale_head <= 0:
amount = (self.number * self.estimated_weight_hd)
return amount

def save(self):
self.estimated_total_weight = self.calc_estimated_weight_total()
super(SaleNote, self).save()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:If statement issue driving me nuts

2014-04-05 Thread Dave Angel
Anthony Smith  Wrote in message:
> Hi
> 
> I have a small project and I have been unable to get the following statement 
> to work. Any help would great.
> User inputs can either self_sale_head which is a $ value,if a $ value is not 
> add a self.estimated_weight_hd is used to get the total weight, 
> the code below should return a estimated_weight_total which can be used for 
> the total sale price. 
> All works when I add the estimated_weight_total manually. I am lost as why.
> 
> def calc_estimated_weight_total(self):
> if self.sale_head <= 0:
> amount = (self.number * self.estimated_weight_hd)
> return amount
> 
> def save(self):
> self.estimated_total_weight = self.calc_estimated_weight_total()
> super(SaleNote, self).save()
> 

Please insert the missing words, and fix the punctuation,  and
 maybe we'll be able to decipher your question.  Your subject line
 implies you think there's a problem with the if statement; 
 perhaps you could describe what problem that is. You might even
 try to describe what the sale_head attribute is supposed to
 be.

Then post a useful fragment of code, and state what resulted,  and
 what you expected that was different.  If you got an exception, 
 paste the whole thing

Ideally post a runnable hunk of code. 

One problem with your first method is that you don't return an
 amount in the (missing) else clause.  So if the condition is
 false, the caller will see None instead of a number. If it
 happens to be called from the save method, you'll get an
 exception. 

-- 
DaveA

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


Re: How can I parse this correctly?

2014-04-05 Thread Anthony Papillion

On Apr 5, 2014, at 23:03, Chris Angelico  wrote:

On Sun, Apr 6, 2014 at 1:52 PM, Anthony Papillion  
 wrote:

When I try to
cast them like this:

print int(row['YEAR'])

I am told by the interpreter:

Traceback (most recent call last):
 File "analyze.py", line 14, in 
   print int(row['MONTH'])
ValueError: invalid literal for int() with base 10: ''

What am I doing wrong? Am I not understanding HOW to cast?


An empty string isn't a valid Python integer, unlike in some other
languages where it's taken as zero. Do you have data in some but not
in others? Should all blank entries be interpreted as zero? (That's
common with a lot of spreadsheets.) Make sure that's really what you
want, and then just do this:

print int(row['MONTH'] or 0)

That'll set a default of zero, if (and only if) the MONTH string is  
blank.


Many thanks! That's exactly what I was looking for. In this case,  
since I'm needing to create a valid date, I'm defaulting to 1.



By the way, is there a reason you're using Python 2 rather than Python
3? For new projects, you ideally should be working with a more recent
version of Python; that way, you won't have to edit your code later,
when you find there's some newer feature that you want. The
differences aren't huge, but the sooner you make the change, the less
code you have to look at


No particular reason at all. I've Bern dabbling in Python for the last  
bit and am just writing code based on the samples or examples I'm  
finding.  What was the tipoff that this was not Python 3? Would there  
be a large difference in this code if it was Python 3?


Anthony
--
https://mail.python.org/mailman/listinfo/python-list


Re: If statement issue driving me nuts

2014-04-05 Thread Gary Herron

On 04/05/2014 09:58 PM, Anthony Smith wrote:

Hi

I have a small project and I have been unable to get the following statement to 
work. Any help would great.
User inputs can either self_sale_head which is a $ value,if a $ value is not 
add a self.estimated_weight_hd is used to get the total weight,
the code below should return a estimated_weight_total which can be used for the 
total sale price.
All works when I add the estimated_weight_total manually. I am lost as why.

def calc_estimated_weight_total(self):
 if self.sale_head <= 0:
 amount = (self.number * self.estimated_weight_hd)
 return amount

def save(self):
 self.estimated_total_weight = self.calc_estimated_weight_total()
 super(SaleNote, self).save()


You'll have to be more informative than that.

Exactly what does "unable to get the following statement to work" mean?  
What did you do to try to get it to work?  What did you get instead?  If 
there was a traceback, please include it in an email.


While you're at it, please also tell us what version of Python, and on 
what hardware you are running -- just in case that matters.


Gary Herron

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


Re: How can I parse this correctly?

2014-04-05 Thread Anthony Papillion

On Apr 5, 2014, at 23:21, Ben Finney  wrote:


Anthony Papillion  writes:


for row in r:
   print row['YEAR']

This works fine. But, I am needing to do date addition/subtraction
using datetime and so I need these dates as integers.


I assume you mean you will be creating ‘datetime.date’ objects. Wh 
at

will you set as the month and day?


Right, I did mean datetime.date. As form month and day, I also have a  
column in my data for that. I'll be pulling it the same way I'm doing  
with year




Alternatively, if you just want to do integer arithmetic on the year,
you don't need the ‘datetime’ module at all.


True. But I do actually need to some date based calculations.  
Basically I'm processing a large data set and calculating time  
intervals between entries




When I try to cast them like this:


Python doesn't have “cast”; instead, you request the creation of  
a new

object by calling the type.


Hmm, interesting. I need to think on that for a moment.  I may well  
have completely misunderstood a major part of Python all this time.



print int(row['YEAR'])


What do you expect this to return when ‘row['YEAR']’ is  
‘""’ (empty

string)?


I expected a defaut value to be returned, perhaps "0". I see now from  
another response that this is not the case and so I've fixed it to read


print int(row['YEAR'] or )




I am told by the interpreter:

Traceback (most recent call last):
 File "analyze.py", line 14, in 
   print int(row['MONTH'])
ValueError: invalid literal for int() with base 10: ''

What am I doing wrong?


You've ignored the condition where your ‘row['YEAR']’ is the empty
string. Python doesn't have an unambiguous integer represented by the
empty string, so it refuses to guess.

You'll need to handle that specially, and decide what value you want
when that's the case.


Thank you! I actually like the fact that it won't simply "fill  
something in". It makes things more predictable and stable.


Anthony
--
https://mail.python.org/mailman/listinfo/python-list


Mutable objects inside tuples - good or bad?

2014-04-05 Thread John Ladasky
I find this programming pattern to be useful... but can it cause problems?

Python 3.3.2+ (default, Feb 28 2014, 00:52:16) 
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [1,2,3]
>>> b = [4,5,6]
>>> c = (a,b)
>>> c
([1, 2, 3], [4, 5, 6])
>>> c[0][0] = 0
>>> c
([0, 2, 3], [4, 5, 6])

Comments appreciated.
-- 
https://mail.python.org/mailman/listinfo/python-list