Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-26 Thread Peter Cacioppi
Steven said -
"In a very real sense, Python is "just" a convenience wrapper around a
bunch of C functions to provide OOP idioms, garbage collection, dynamic
typing, runtime introspection, exceptions, and similar. "


I can't really disagree with you in a factual sense, but somehow it doesn't 
really convey the right flavor.

The success or failure of a project (or an entire company) can rest on the 
correct choice of programming language. Whether you failed because you were 
pursuing an impossible task or merely a very, very, very hard one is sort of 
semantics, and cold comfort to the those affected.

Maybe I'm biased because I'm walking away from a six figure job coding Java and 
C for a large company to write Python for a tiny non-profit.

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


Re: Processing large CSV files - how to maximise throughput?

2013-10-26 Thread Walter Hurry
On Thu, 24 Oct 2013 18:38:21 -0700, Victor Hooi wrote:

> Hi,
> 
> We have a directory of large CSV files that we'd like to process in
> Python.
> 
> We process each input CSV, then generate a corresponding output CSV
> file.
> 
> input CSV -> munging text, lookups etc. -> output CSV
> 
> My question is, what's the most Pythonic way of handling this? (Which
> I'm assuming
> 
> For the reading, I'd
> 
> with open('input.csv', 'r') as input, open('output.csv', 'w') as
> output:
> csv_writer = DictWriter(output)
> for line in DictReader(input):
> # Do some processing for that line...
> output = process_line(line)
> # Write output to file csv_writer.writerow(output)
> 
> So for the reading, it'll iterates over the lines one by one, and won't
> read it into memory which is good.
> 
> For the writing - my understanding is that it writes a line to the file
> object each loop iteration, however, this will only get flushed to disk
> every now and then, based on my system default buffer size, right?
> 
> So if the output file is going to get large, there isn't anything I need
> to take into account for conserving memory?
> 
> Also, if I'm trying to maximise throughput of the above, is there
> anything I could try? The processing in process_line is quite line -
> just a bunch of string splits and regexes.
> 
> If I have multiple large CSV files to deal with, and I'm on a multi-core
> machine, is there anything else I can do to boost throughput?
> 
I'm guessing that the idea is to load the output CSV into a database.

If that's the case, why not load the input CSV into some kind of staging 
table in the database first, and do the processing there?

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


Obfuscated factorial

2013-10-26 Thread Steven D'Aprano
Just for fun:


class Numberator:
def __init__(self, number):
self.__number = number
def evaluate(self):
return self.__number

class Multiplier:
def __init__(self, multiplier, multiplicand):
self.multiplier = multiplier
self.multiplicand = multiplicand
def evaluate(self):
return self.multiplier * self.multiplicand.evaluate()

class FactorialBuilder:
def __init__(self, number):
if not isinstance(number, int):
raise TypeError
if number < 0:
raise ValueError
self.__number = number
def build(self):
multiplicand = Numberator(1)
for n in range(2, self.__number + 1):
multiplicand = Multiplier(n, multiplicand)
return Factorialiser(multiplicand)

class Factorialiser:
def __init__(self, evaluatorix):
self.__evaluatorix = evaluatorix
def calculate(self):
return self.__evaluatorix.evaluate()

for i in range(16):
print(i, FactorialBuilder(i).build().calculate())



And the output is:

0 1
1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800
11 39916800
12 479001600
13 6227020800
14 87178291200
15 1307674368000



It goes without saying that this isn't Pythonic :-)


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


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread rusi
On Saturday, October 26, 2013 8:10:16 AM UTC+5:30, Steven D'Aprano wrote:
> Your personal attacks are not appreciated. Why can you not accept that 
> people who post using GG's defaults cause pain and difficulty to many -- 
> probably the great majority -- of readers who use either the mailing list 
> or the news group to read this list? Don't you think that they are 
> entitled to complain when people repeatedly post double-spaced, hard to 
> read messages, or set the reply address wrongly, or include no context or 
> attributes, or all of the above at once?
> 
> 
> Do you really intend to say that we have no right to complain about how 
> difficult Google Groups makes it for us?

I think you are mixing up cause and effect, symptom and disease, Steven.

The symptoms are
1. Double spaced responses
2. Non/improper attribution
3. Generally idiotic behavior

The 'disease' is:

Google-groups is current technology whereas newsgroups/feeds etc is pre-www 
technology.

By fairly straightforward statistics -- you should know given the newest module 
in python 3.4  -- the probability of idiotic behavior in a bunch of 
children is going to be significantly higher than the same in a bunch of adults.

Google-groups consist of the 'children-population' (so to speak); newsgroups 
etc consist of the adult population with some exceptions.

The appropriate way of dealing with children is not to say "Dont be children!" 
but to say "This kind of behavior is unacceptable out here"

I feel the biggest negative consequence of the anti-GG rhetoric is that the 
bigger issue -- idiotic behavior -- is left unaddressed in favor of very minor 
local issues like double-spaced mails.




> So far Peter
> Cacioppi is one of those people. He has shown no inclination that he is
> willing to take the care to communicate well according to the community
> standards here, and he has shown a distressing tendency towards snarky,
> arrogant responses to polite requests to fix his posts. 

I think its fairly straightforward to fix these issues:
First (for complete newbies) one ignores the problem and engages/answers 
discusses
Then one mildly mentions that this -- double-spacing/non-attribution whatever 
-- is causing a problem; eg the footnote that Mark (used to) keep
Then more strongly
Then finally give no response to the question under discussion except to point 
out and underscore the idiotic behavior -- just make sure that the claim of 
Peter -- "this group is working for me" -- is not kept true.

tl;dr I think Mark's scoldings in this regard will work if they come not just 
from him but from any and every one.  They are likely to have a larger 
subscription if you would agree to change: "Dont use GG!!"
to
"Users of GG are requested to read and follow these instructions
https://wiki.python.org/moin/GoogleGroupsPython "
-- 
https://mail.python.org/mailman/listinfo/python-list


Cookie issue(cant fix it with anyhting)

2013-10-26 Thread Nick the Gr33k
Hello i having the following code to try and retrieve the visitor's 
saved cookie form the browser.


[CODE]
# initialize cookie and retrieve cookie from clients browser
try:
cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )
cookieID = cookie['name'].value
except:
cookieID = 'visitor'
[/CODE]

It works as expected except form the fact from when the visitor enters 
my webpage(superhost.gr) by clicking a backlink of another webpage.


Then even if the cookie exists in his browser for some reason the try 
fails and except take actions.


Can somebody explain why this is happening?

You can see this action yourself by hitting:

1. superhost.gr as a direct hit
2. by clicking superhost.gr's backlink from ypsilandio.gr/mythosweb.gr

You will see than in 2nd occasion another ebtry will appear in the 
database here:


http://superhost.gr/?show=log&page=index.html
--
https://mail.python.org/mailman/listinfo/python-list


Re: Obfuscated factorial

2013-10-26 Thread Vito De Tullio
Steven D'Aprano wrote:

> Just for fun:

[...]

you miss a FactoryFactory and a couple of *Manager.

Oh, and it should be xml-config-driven.


-- 
By ZeD

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


Re: Don't use default Google Group client

2013-10-26 Thread Ben Finney
rusi  writes:

> On Saturday, October 26, 2013 8:10:16 AM UTC+5:30, Steven D'Aprano wrote:
> > Do you really intend to say that we have no right to complain about
> > how difficult Google Groups makes it for us?
>
> I think you are mixing up cause and effect, symptom and disease, Steven.
>
> The symptoms are
> 1. Double spaced responses
> 2. Non/improper attribution

Both of which are Google Groups failing to implement established
standard interfaces.

> The 'disease' is:
>
> Google-groups is current technology

Google Groups attempts to interface with standard protocols of
communication, and gets it wrong. Google are well-informed of the ways
in which Google Groups is misbehaving, and they are disinclined to fix
the misbehaviour.

> whereas newsgroups/feeds etc is pre-www technology.

So what? Much of the internet is pre-WWW, too. That doesn't excuse the
misbehaviour of software which purports to interface with standard
protocols but gets them wrong.

To the extent that the mis-implementation of Google Groups makes
messages from there more difficult to read, its users should be
agitating for Google to fix the service, and/or switching to software
which conforms to standards better.

-- 
 \“Visitors are expected to complain at the office between the |
  `\ hours of 9 and 11 a.m. daily.” —hotel, Athens |
_o__)  |
Ben Finney

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


Re: Obfuscated factorial

2013-10-26 Thread Chris Angelico
On Sat, Oct 26, 2013 at 11:50 PM, Vito De Tullio
 wrote:
> you miss a FactoryFactory and a couple of *Manager.
>
> Oh, and it should be xml-config-driven.

Or a metaclass and a few decorators. They're inherently Pythonic, right?

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


Cookie fucking problem

2013-10-26 Thread Nick the Gr33k
Hello i having the following code to try and retrieve the visitor's 
saved cookie form the browser.


[CODE]
# initialize cookie and retrieve cookie from clients browser
try:
cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )
cookieID = cookie['name'].value
except:
cookieID = 'visitor'
[/CODE]

It works as expected except form the fact from when the visitor enters 
my webpage(superhost.gr) by clicking a backlink of another webpage.


Then even if the cookie exists in his browser for some reason the try 
fails and except take actions.


Can somebody explain why this is happening?

You can see this action yourself by hitting:

1. superhost.gr as a direct hit
2. by clicking superhost.gr's backlink from ypsilandio.gr/mythosweb.gr

You will see than in 2nd occasion another ebtry will appear in the 
database here:


http://superhost.gr/?show=log&page=index.html
--
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie issue(cant fix it with anyhting)

2013-10-26 Thread Chris Angelico
On Sat, Oct 26, 2013 at 11:29 PM, Nick the Gr33k  wrote:
> Can somebody explain why this is happening?

SONG--ERNEST  [1]
Were I a king in very truth,
And had a son--a guileless youth--
  In probable succession;
To teach him patience, teach him tact,
How promptly in a fix to act,
He should adopt, in point of fact,
  A webmaster's profession.

Slow down. Stop panicking. You have posted this same question several
times, and each time you have not received a response because this is
NOT A PYTHON QUESTION. Pardon my raised voice, but I've just finished
a season of Princess Ida, where I'd call "HEADS UP UPSTAGE, BAR
MOVING!" from the fly tower down to the stage. You have been given
multiple avenues to explore, and you have not given any evidence that
you have explored them. Spend some time getting to know the
technologies you're trying to use. Buy a book if it helps. Take a
formal course, maybe. Whatever it takes, gain a bit of competence
before you try to make things work. At the moment, you're just poking
into a black box and hoping the right magic will happen, and then
panicking here to python-list whenever the wrong magic happens.

[1] http://math.boisestate.edu/gas/grand_duke/web_op/gd03.html

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


Re: Cookie fucking problem

2013-10-26 Thread Chris Angelico
Oh! Now you have a quite different problem. I'm sure your email spam
will have plenty of offers from lovely ladies who are willing to
satisfy your needs, you really don't want to be getting intimate with
cookies.

And if that's not what you meant, then kindly refrain from posting
duplicate threads just to add profanity to the subject line. Thanks!

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


Re: Cookie fucking problem

2013-10-26 Thread Ben Finney
Nick the Gr33k  writes:

> Hello i having the following code to try and retrieve the visitor's
> saved cookie form the browser.

The fact that you've posted Python code does not make this a Python
question. Your issue is with HTTP cookies, as you have been told several
times.

This is irrelevant to the Python discussion group, yet you keep
clamouring here for attention. Please do not ask here for education
about HTTP again.

-- 
 \ “I have yet to see any problem, however complicated, which, |
  `\  when you looked at it in the right way, did not become still |
_o__)more complicated.” —Paul Anderson |
Ben Finney

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


Re: Cookie fucking problem

2013-10-26 Thread Yaşar Arabacı
I didn't follow the thread, I am sorry if this is duplicate, but don't
catch all Exceptions, catch only the ones you expect, so that you can
identify unexpected errors:

cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )
try:
cookieID = cookie['name'].value
except KeyError:
cookieID = 'visitor'

-- 
http://ysar.net/
-- 
https://mail.python.org/mailman/listinfo/python-list


Printing a drop down menu for a specific field.

2013-10-26 Thread Nick the Gr33k

[QUOTE=turvey]Say your data is like the following:
data = [('alice', 1), ('alice', 2), ('bob', 5), ('bob', 10), ('carrie', 3)]

Where the first entry is your user and the second entry is a timestamp. 
Your data is structured basically like this, except I stripped the 
irrelevant details.


[CODE]
user_to_timestamps = {}

# Gather all your users together.
for user,timestamp in data:
if user not in user_to_timestamp:
user_to_timestamp[user] = []
user_to_timestamp[user].append(timestamp)

# You now have a data structure like this
# {'alice': [1, 2], 'bob': [5, 10], 'carrie': [3]}

for user, timestamps in user_to_timestamps.iteritems():
print user
for timestamp in timestamps:
print "%s" % timestamp
[/CODE]

There. That's how you would do it. It shouldn't be much work to get your 
code into that form.[/QUOTE]


I'am sorry but i still cannot transform my code:

[CODE]
try:
		cur.execute( '''SELECT host, city, useros, browser, ref, hits, 
lastvisit FROM visitors
		WHERE counterID = (SELECT ID FROM counters WHERE url = %s) ORDER 
BY lastvisit DESC''', page )

data = cur.fetchall()

for row in data:
(host, city, useros, browser, ref, hits, lastvisit) = 
row
lastvisit = lastvisit.strftime('%A %e %b, %H:%M')

print( "" )
for item in (host, city, useros, browser, ref, hits, 
lastvisit):
print( " %s 
" % item )
except pymysql.ProgrammingError as e:
print( repr(e) )
[/CODE]

to the solution you presented :(
I just dont know how to write it.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie fucking problem

2013-10-26 Thread Mark Lawrence

On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread rurpy
On 10/25/2013 06:25 PM, Chris Angelico wrote:
> On Sat, Oct 26, 2013 at 10:44 AM,   wrote:
>> Peter, you can ignore Terry's "advice" if Google Groups works for you.
>> There are a small number of Google haters here who seem larger due to
>> their obnoxious noisiness.
>>
>> I've been using Google Groups to post here for many years and with a
>> little care it is usable without annoying anyone except a few drooling
>> fanatics.  All access methods have pros and cons (and I've posted here
>> about many of TB numerous cons) so if the usability tradeoff favors
>> GG for you (or anyone else) I recommend you not be intimidated by
>> the anti-GG goon squad.
> 
> As soon as we hear of people automatically blacklisting any posts that
> come from Thunderbird, I'll believe you that they're on par. Until
> then, no matter how courteous you might be in your use of GG (which
> still makes you part of an extremely small minority), you still have a
> fundamental downside in that your message simply won't get to
> everyone.

I am aware of that.  As I said the last time the subject came up,

* So what?  Anyone too lazy or with too much need to control, to
 not skip over posts they find annoying probably is someone unlikely
 to offer anything constructive in any thread I'm participating
 in.

* It is not at all clear that the number who actually completely
 ignore GG is more than a very small number.

* Life's full of tradeoffs.  The convenience of GG to some people
 is worth the downside.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie fucking problem

2013-10-26 Thread Nick the Gr33k

Στις 26/10/2013 5:34 μμ, ο/η Mark Lawrence έγραψε:

On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


No need, i can practice with your mother.

--
What is now proved was at first only imagined! & WebHost

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


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread rurpy
On 10/25/2013 06:19 PM, Mark Lawrence wrote:
> On 26/10/2013 00:44, [email protected] wrote:
>> On 10/25/2013 02:05 PM, Terry Reedy wrote:
>>> On 10/25/2013 2:57 PM, Peter Cacioppi wrote:
 The default
 Google Group client is notoriously cruddy with quotes attribution.
>>>
>>> So don't use it. Get any decent newsreader, such as Thunderbird, and
>>> access the list at news.gmane.org as gmane.comp.python.general.
>>
>> Peter, you can ignore Terry's "advice" if Google Groups works for you.
>> There are a small number of Google haters here who seem larger due to
>> their obnoxious noisiness.
>>
>> I've been using Google Groups to post here for many years and with a
>> little care it is usable without annoying anyone except a few drooling
>> fanatics.  All access methods have pros and cons (and I've posted here
>> about many of TB numerous cons) so if the usability tradeoff favors
>> GG for you (or anyone else) I recommend you not be intimidated by
>> the anti-GG goon squad.
> 
> Thunderbird cons - I've never known any. 

That's odd, because in 
  https://groups.google.com/d/msg/comp.lang.python/FFAe5sJ7kQ4/GmDtHitY50QJ
I responded to a direct question from you about problems 
with Thunderbird.  If you mean instead that because *you've* 
experienced no problems, then none exist, that's your business
but I hope you don't carry that attitude into your programming 

Further, that post was only with technical issues related to 
TB; in another thread in which you participated, I explained 
some of the other usability tradeoffs, issues of personal 
choice and preference which clearly vary between users, for 
example in:
  https://groups.google.com/d/msg/comp.lang.python/Rxw7H4yNGh4/WRZDOzZd76oJ
  https://groups.google.com/d/msg/comp.lang.python/Rxw7H4yNGh4/41hZ3Si5G0cJ
  https://groups.google.com/d/msg/comp.lang.python/Rxw7H4yNGh4/jKu57BLvqIUJ
I question your judgement if you see you own preferences for 
TB as being absolute and applicable to everyone.  The idea 
that there exists any access method for reading this list 
that has *no* cons is ludicrous.

> Google groups cons - continual 
> streams of messages on a daily basis that are double spaced despite 
> umpteen requests to follow instructions so the crap doesn't get 
> repeated.  Just how difficult is it?  Are you prepared to pay for my new 
> glasses, as the eye strain caused by google crap really does get to me. 

You are being absurd.  If you are seriously willing to damage 
your eyesight because you feel compelled to read every post
here then you should seek psychological help right away.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread rurpy
On 10/25/2013 06:35 PM, Terry Reedy wrote:
> On 10/25/2013 7:44 PM, [email protected] wrote:
>> On 10/25/2013 02:05 PM, Terry Reedy wrote:
>>> On 10/25/2013 2:57 PM, Peter Cacioppi wrote:
 The default
 Google Group client is notoriously cruddy with quotes attribution.
>>>
>>> So don't use it. Get any decent newsreader, such as Thunderbird, and
>>> access the list at news.gmane.org as gmane.comp.python.general.
>>
>> Peter, you can ignore Terry's "advice" if Google Groups works for you.
> 
> Rurpy: My advice was real advice (what I do) given in response to 
> Cacioppi's complaint 'notoriously cruddy'.

As was mine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread rurpy
On 10/25/2013 08:40 PM, Steven D'Aprano wrote:
> On Fri, 25 Oct 2013 16:44:45 -0700, rurpy wrote:
>> On 10/25/2013 02:05 PM, Terry Reedy wrote:
>>> On 10/25/2013 2:57 PM, Peter Cacioppi wrote:
 The default
 Google Group client is notoriously cruddy with quotes attribution.
>>> 
>>> So don't use it. Get any decent newsreader, such as Thunderbird, and
>>> access the list at news.gmane.org as gmane.comp.python.general.
>> 
>> Peter, you can ignore Terry's "advice" if Google Groups works for you.
>> There are a small number of Google haters here who seem larger due to
>> their obnoxious noisiness.
> 
> There are people here who hate Google Groups but simply don't chime in. 
> I'm one of them. Perhaps I should.
> 
> There are also many people who have a blanket "ignore" switch on anything 
> coming from GG, not out of any personal vendetta against you, but simply 
> out of self-defence. They don't say anything simply because they don't 
> see the posts.

They see the replies so they have every opportunity to reply.
I would hope the reason they don't is because they don't want 
to contribute to the already way too voluminous insults, flames,
nit-picking, troll-baiting and other non-python related garbage 
here.

>> I've been using Google Groups to post here for many years and with a
>> little care it is usable without annoying anyone 
> 
> This is true, and thank you for taking that care, that is really 
> appreciated.
> 
> But perhaps you should consider that although GG works for you, it 
> doesn't work for many people who don't take that care. So far Peter 
> Cacioppi is one of those people. He has shown no inclination that he is 
> willing to take the care to communicate well according to the community 
> standards here, and he has shown a distressing tendency towards snarky, 
> arrogant responses to polite requests to fix his posts.

I hadn't read this whole thread, I just wanted to provide an 
alternative point of view to that expressed by Terry Reedy
re Google Groups (since I use it myself).

However, looking now, I see you pointed out that Peter originally 
cross-posted his two messages to four groups:

 alt.comp.lang.c: 4 posts total
  one (serious, on-topic [*1], non-snarky) reply and a reply from OP.

 alt.comp.lang.borland-delphi: 4 posts total
  same as above

 alt.lang.asm: 6 posts total
  three (serious, on-topic, non-snarky) replies and a reply from the OP

 comp.lang.python: 26 posts and counting
  Two immediate not-on-topic responses, one polite but a little haughty
  (what made the author assume that everyone has a weblog to post to?)
  and one, from *you*, clearly snarky:
   > Oh look, your post was cross-posted to no fewer than four
   > newsgroups. What a surprise!
  Ironic that you are complaining about snarkiness from the OP.
  Those were followed (unsurprisingly) by a snarky response from the
  OP and then (currently and counting) 26 replies, many snarky, none
  addressing the OP's topic and none directly Python related.

Perhaps the snarkiness you complain about came from other earlier
threads, but I did see anything that struck me as horrible in a brief 
sampling.

Why didn't you and the other respondents just ignore the above post, 
likely leading to the same results as in the other three groups?
Instead we are all treated to yet another endless thread (with forked
subject lines making it even harder to avoid) of non-Python related 
verbal pissing.

>> except a few drooling
>> fanatics.  All access methods have pros and cons (and I've posted here
>> about many of TB numerous cons) so if the usability tradeoff favors GG
>> for you (or anyone else) I recommend you not be intimidated by the
>> anti-GG goon squad.
> 
> Your personal attacks are not appreciated. 

What I wrote was a non-personal attack.

> Why can you not accept that 
> people who post using GG's defaults cause pain and difficulty to many -- 

"Pain"?  If you really suffer pain from reading badly formatted 
posts you should consider the advice I gave to Mark Lawrence.
But ignoring the exaggerations, I can and do accept it causes 
some degree of annoyance -- it annoys me as well, and I've no
clue where you got the idea that it didn't.  But it is also 
annoying for many infrequent posters to go though the effort 
to set up a news group reader or deal with a lot of email from 
a high-volume mailing list.  And it is annoying for readers to
wade though the constant torrent of bitching by GG bashers. 
Of course I understand that you consider your annoyances more 
important that other people's but then don't we all.

I am irritated by things here too: people who haven't 
learned to tell the difference between "fact" and "my opinion", 
people who feel free to be blunt to the point of offensiveness
in their posts but who take offense at the mildest slight 
directed at them, people who can tell on the basis of a post 
or two if a question is homework or a poster is drunk or lying 
about a college degree, people who respond t

Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread rurpy
On 10/26/2013 06:15 AM, rusi wrote:
>[...]
> Google-groups consist of the 'children-population' (so to speak);
> newsgroups etc consist of the adult population with some exceptions.
> The appropriate way of dealing with children is not to say "Dont be
> children!" but to say "This kind of behavior is unacceptable out
> here"
>[...]

This is exactly the kind of trash-talk that provokes so much discord 
here.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie fucking problem

2013-10-26 Thread Mark Lawrence

On 26/10/2013 15:55, Nick the Gr33k wrote:

Στις 26/10/2013 5:34 μμ, ο/η Mark Lawrence έγραψε:

On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


No need, i can practice with your mother.



An interesting combination of stupid, tight fisted and a necrophiliac.

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Cookie fucking problem

2013-10-26 Thread Nick the Gr33k

Στις 26/10/2013 6:21 μμ, ο/η Mark Lawrence έγραψε:

On 26/10/2013 15:55, Nick the Gr33k wrote:

Στις 26/10/2013 5:34 μμ, ο/η Mark Lawrence έγραψε:

On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


No need, i can practice with your mother.



An interesting combination of stupid, tight fisted and a necrophiliac.


Αντε απο εδω ρε αφιονισμενη πουτσοτριχα.

--
What is now proved was at first only imagined! & WebHost

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


Re: Obfuscated factorial

2013-10-26 Thread Joshua Landau
On 26 October 2013 12:55, Steven D'Aprano
 wrote:
> Just for fun:
...
> for i in range(16):
> print(i, FactorialBuilder(i).build().calculate())

Python already supports the factorial operator, -ⵘ. You just have to import it.

# Import statement
ⵘ = type("",(),{"__rsub__":lambda s,n:(lambda f,n:f(f,n))(lambda
f,z:round((2.5066282746310002*(z+0j+7.5)**(z+0.5)*2.718281828459045**(-z-7.5)*(0.80993+676.5203681218851/(z+1)-1259.1392167224028/(z+2)+771.32342877765313/(z+3)-176.61502916214059/(z+4)+12.507343278686905/(z+5)-0.13857109526572012/(z+6)+9.9843695780195716e-6/(z+7)+1.5056327351493116e-7/(z+8))).real)if
z>=0.5 else 
3.141592653589793/(__import__("math").sin(3.141592653589793*z)*f(f,1-z)),n)})()

assert 2-ⵘ == 2

assert 3-ⵘ == 6

assert 4-ⵘ == 24
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Obfuscated factorial

2013-10-26 Thread Tim Chase
On 2013-10-27 00:26, Chris Angelico wrote:
> On Sat, Oct 26, 2013 at 11:50 PM, Vito De Tullio
>  wrote:
> > you miss a FactoryFactory and a couple of *Manager.
> >
> > Oh, and it should be xml-config-driven.
> 
> Or a metaclass and a few decorators. They're inherently Pythonic,
> right?

You are deploying it to The Cloud™ right?  And where is the
horizontal scalability?  Why doesn't it use NoSQL?

Bah, just goes to show that Python is no good for Enterprise™
applications ;-)

-tkc








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


Logging timezones

2013-10-26 Thread Joseph L. Casale
The default converter attribute uses localtime, but often under windows when
I add an additional logger, create a new file handler and set a formatter the 
time
switches to utc.

Obviously redefining a new converter class does nothing as the default is what I
wanted to start with, localtime.

Anyone experienced this and have a workaround?

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


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread Mark Lawrence

On 26/10/2013 15:58, [email protected] wrote:



That's odd, because in
   https://groups.google.com/d/msg/comp.lang.python/FFAe5sJ7kQ4/GmDtHitY50QJ
I responded to a direct question from you about problems
with Thunderbird.  If you mean instead that because *you've*
experienced no problems, then none exist, that's your business
but I hope you don't carry that attitude into your programming



Would you please be kind enough to quote the question that I asked. 
You'll find it extremely difficult as I actually made a stement.  I quote


"
> Please provide evidence that Thunderbird is buggy.  I use it quite
> happily, don't have problems, and have never seen anybody complaining
> about it.
"

I still stand by the above statement, whereas as a constant stream of 
crap arrives here every day from the bug ridden google product(s).  How 
can you ignore it until you've actually looked at it?  Do you have 
Superman's eyesight?


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: decorators and mangled names for "private" methods

2013-10-26 Thread Tim Chase
On 2013-10-25 22:01, Peter Otten wrote:
> > from functools import wraps
> > class require_keys:
> >   def __init__(self, *keys):
> > self.keys = keys
> >   def __call__(decorator_self, fn):
> > @wraps(fn)
> > def result_fn(method_self, *args, **kwargs):
> >   # import pdb; pdb.set_trace()
> >   req = method_self.__private()  
> 
> The above __private literal is in the (statically determined)

I guess the static determination is/was what threw me.  I'd have
figured that Python wouldn't care what method-name/attribute I looked
up, until such time as the code was actually executed, at which
point it would be evaluated in the context of Foo, not the
require_keys decorator.

For now, I'll just smash the code a bit and un-privatize the
functions (it's hand-me-down code from a C/C++ programmer, so there
are a lot of C++isms in the source).

-tkc



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


Re: Printing a drop down menu for a specific field.

2013-10-26 Thread Nick the Gr33k

Στις 26/10/2013 5:10 μμ, ο/η Nick the Gr33k έγραψε:

[QUOTE=turvey]Say your data is like the following:
data = [('alice', 1), ('alice', 2), ('bob', 5), ('bob', 10), ('carrie', 3)]

Where the first entry is your user and the second entry is a timestamp.
Your data is structured basically like this, except I stripped the
irrelevant details.

[CODE]
user_to_timestamps = {}

# Gather all your users together.
for user,timestamp in data:
 if user not in user_to_timestamp:
 user_to_timestamp[user] = []
 user_to_timestamp[user].append(timestamp)

# You now have a data structure like this
# {'alice': [1, 2], 'bob': [5, 10], 'carrie': [3]}

for user, timestamps in user_to_timestamps.iteritems():
 print user
 for timestamp in timestamps:
 print "%s" % timestamp
[/CODE]

There. That's how you would do it. It shouldn't be much work to get your
code into that form.[/QUOTE]

I'am sorry but i still cannot transform my code:

[CODE]
 try:
 cur.execute( '''SELECT host, city, useros, browser, ref, hits,
lastvisit FROM visitors
 WHERE counterID = (SELECT ID FROM counters
WHERE url = %s) ORDER BY lastvisit DESC''', page )
 data = cur.fetchall()

 for row in data:
 (host, city, useros, browser, ref, hits, lastvisit) = row
 lastvisit = lastvisit.strftime('%A %e %b, %H:%M')

 print( "" )
 for item in (host, city, useros, browser, ref, hits,
lastvisit):
 print( " %s " %
item )
 except pymysql.ProgrammingError as e:
 print( repr(e) )
[/CODE]

to the solution you presented :(
I just dont know how to write it.


Can someone write this properly? i tried but cannot make it work.

--
What is now proved was at first only imagined! & WebHost

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


Re: Cookie issue(cant fix it with anyhting)

2013-10-26 Thread Steven D'Aprano
On Sat, 26 Oct 2013 15:29:52 +0300, Nick the Gr33k wrote:

> Can somebody explain why this is happening?

It is the same answer that you were told the last time you asked this 
question, and the previous time you asked this question. And it will be 
the same answer the next time you ask.


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


Re: Cookie fucking problem

2013-10-26 Thread Mark Lawrence

On 26/10/2013 16:25, Nick the Gr33k wrote:

Στις 26/10/2013 6:21 μμ, ο/η Mark Lawrence έγραψε:

On 26/10/2013 15:55, Nick the Gr33k wrote:

Στις 26/10/2013 5:34 μμ, ο/η Mark Lawrence έγραψε:

On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


No need, i can practice with your mother.



An interesting combination of stupid, tight fisted and a necrophiliac.


Αντε απο εδω ρε αφιονισμενη πουτσοτριχα.



I could almost feel sorry for you.  But the more of your time I waste 
the longer it'll take you to get your website working.  Did you ever 
stop to think about that?  Or are you too busy trolling hundreds of 
other mailing lists in parallel with this?  T


Thinking about my late mum I reckon she'd forgotten more about websites 
than you've ever learned, and she knew nothing about them.


Keep wasting your time here moron, I'm really getting into top gear with 
you now.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Cookie fucking problem

2013-10-26 Thread Ned Batchelder

On 10/26/13 11:21 AM, Mark Lawrence wrote:

On 26/10/2013 15:55, Nick the Gr33k wrote:

Στις 26/10/2013 5:34 μμ, ο/η Mark Lawrence έγραψε:

On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


No need, i can practice with your mother.



An interesting combination of stupid, tight fisted and a necrophiliac.



The only way to stop Nikos threads is to stop responding.  Your replies 
are part of the problem here.  Please stop.


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


Re: Cookie fucking problem

2013-10-26 Thread Steven D'Aprano
On Sat, 26 Oct 2013 16:27:03 +0300, Nick the Gr33k wrote:

>> Can somebody explain why this is happening?

Yes, anyone who reads the answer that was given the first time you asked 
this question will be able to explain why this is happening. The answer 
hasn't changed from the first time you asked, or the second time, or the 
third time. And it will remain the same answer the next time you ask.

You can ask this question ten times, a hundred times, a thousand times, 
and the answer will not change. Go back and read the responses from the 
first time you asked. That was only a few weeks back. Read them. If you 
don't understand the answer, feel free to point out which part of the 
answer you don't understand. If you just repeat the question, you will 
get the same answer again: read the answer given the first time you asked.


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


Re: Cookie fucking problem

2013-10-26 Thread Steven D'Aprano
On Sat, 26 Oct 2013 15:34:23 +0100, Mark Lawrence wrote:

> On 26/10/2013 14:27, Nick the Gr33k wrote:
> 
> Buy a sex manual.

Mark, please resist the urge to bait Nick with insults. As entertaining 
as they may be, they don't actually help reduce the problem.



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


Re: Cookie fucking problem

2013-10-26 Thread rusi
On Saturday, October 26, 2013 9:20:40 PM UTC+5:30, Mark Lawrence wrote:
> 
> I could almost feel sorry for you.  But the more of your time I waste 
> the longer it'll take you to get your website working.  Did you ever 
> stop to think about that?  Or are you too busy trolling hundreds of 
> other mailing lists in parallel with this?  T
> 
> 
> Thinking about my late mum I reckon she'd forgotten more about websites 
> than you've ever learned, and she knew nothing about them.
> 
> Keep wasting your time here moron, I'm really getting into top gear with 
> you now.

I happen to be among those who find your humour funny, Mark including the 
appositeness of your first rejoinder on this thread, considering the subject 
title.

After that its tasteless and disgusting.
So...
If you want to be funny please desist
[If you want to be disgusting you may persist]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie fucking problem

2013-10-26 Thread Mark Lawrence

On 26/10/2013 17:00, Steven D'Aprano wrote:

On Sat, 26 Oct 2013 15:34:23 +0100, Mark Lawrence wrote:


On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


Mark, please resist the urge to bait Nick with insults. As entertaining
as they may be, they don't actually help reduce the problem.





I promise to stop baiting this complete and utter moron when I observe 
that nobody on this group says a single word to him as that's the only 
message that he'll understand.  Any word to him from anybody and I 
reserve the right to join in.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Printing a drop down menu for a specific field.

2013-10-26 Thread Steven D'Aprano
On Sat, 26 Oct 2013 18:40:52 +0300, Nick the Gr33k wrote:

> Can someone write this properly? i tried but cannot make it work.

Start by writing down what problem you are trying to solve with this 
code, and what you expect the code to do. In detail. What input data does 
it take, what result should it produce.

Then write down, in Greek, how *you* would solve this problem, again, in 
detail. What steps would *you* take? If you don't know how to solve the 
problem in real life, how do you expect to write instructions for a 
computer to solve it?

Once you know how to solve the problem yourself, then you need to change 
those steps into steps the computer can perform. Then, and only then, 
should you even think about writing Python code.

That is what programmers do. Since you want to be a programmer, you need 
to learn how to do this. Good luck! It's lots of hard work, and sometimes 
time consuming. That's all part of the job.


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


Re: Cookie fucking problem

2013-10-26 Thread Mark Lawrence

On 26/10/2013 17:05, rusi wrote:

On Saturday, October 26, 2013 9:20:40 PM UTC+5:30, Mark Lawrence wrote:


I could almost feel sorry for you.  But the more of your time I waste
the longer it'll take you to get your website working.  Did you ever
stop to think about that?  Or are you too busy trolling hundreds of
other mailing lists in parallel with this?  T


Thinking about my late mum I reckon she'd forgotten more about websites
than you've ever learned, and she knew nothing about them.

Keep wasting your time here moron, I'm really getting into top gear with
you now.


I happen to be among those who find your humour funny, Mark including the 
appositeness of your first rejoinder on this thread, considering the subject 
title.

After that its tasteless and disgusting.
So...
If you want to be funny please desist
[If you want to be disgusting you may persist]



Sorry me old son but my humour has developed over 40 years to cover how 
naturally quiet and shy I am, it ain't gonna change now.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Sexism in the Ruby community: how does the Python community manage it?

2013-10-26 Thread Steven D'Aprano
On Wed, 16 Oct 2013 23:13:33 -0400, Owen Jacobson wrote:

> Last week, Elad Maidar wrote a fairly short but readable opinion
> piece[0] illustrating some long-standing social problems in the Ruby
> community,
[...]

Well, this has been a big disappointment. The author of this post, Owen 
Jacobson, appears to have made a fly-by post. Despite asking three 
questions, there's no sign that Owen stuck around to hear the answers. 
Pity, I would have been interested to hear what he had to say.


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


Re: Python was designed

2013-10-26 Thread Paul Rubin
Peter Cacioppi  writes:
>> Challenge: give some examples of things which you can do in Python, but
>> cannot do *at all* in C, C++, C#, Java? 
> Please. No exceptions is huge. No garbage collection is huge. 
> But you can do anything with a Turing machine. ...

Lumping C, C++, C#, and Java together misses the most important thing.
Python, C#, and Java all have a vital capability, that's inherently
missing from C and C++, and it's not garbage collection.  Namely, you
get the ability to write a program and have the assurance that bugs in
your code won't overwrite memory at random or make the program segfault.
You instead get a reasonable stack trace saying what was going on when
the error happened.

To riff on Benjamin Pierce, programming is not just about letting you
supply the presence of given behaviors (any sane Turing-complete
language lets you do that).  It's also about ensuring the -absence- of
other behaviors, and that in fact is where the heavy lifting of language
design is mostly directed.

FYI, there is real though imprecise garbage collection for C.  Web
search for "Boehm garbage collection" should find more info.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread Steven D'Aprano
On Sat, 26 Oct 2013 08:05:27 -0700, rurpy wrote:

> On 10/25/2013 08:40 PM, Steven D'Aprano wrote:
[...]
> However, looking now, I see you pointed out that Peter originally
> cross-posted his two messages to four groups:

I think you are confused. I haven't said anything about Peter Cacioppi 
cross-posting. To the best of my knowledge, he hasn't cross-posted 
anything here.



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


Check if this basic Python script is coded right

2013-10-26 Thread HC
I'm doing my first year in university and I need help with this basic 
assignment.

Assignment: Write Python script that prints sum of cubes of numbers between 
0-200 that are multiples of 3. 3^3+6^3+9^3+12^3+198^3=?

My script:
count = 0
answer = 0

while count<200:
if count%3==0:
answer = answer + count**3
count = count + 1

print ("Result is: " +str(answer))

Is it all okay?

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


Re: Check if this basic Python script is coded right

2013-10-26 Thread Joel Goldstick
On Sat, Oct 26, 2013 at 1:36 PM, HC  wrote:
> I'm doing my first year in university and I need help with this basic 
> assignment.
>
> Assignment: Write Python script that prints sum of cubes of numbers between 
> 0-200 that are multiples of 3. 3^3+6^3+9^3+12^3+198^3=?
>
> My script:
> count = 0
> answer = 0
>
> while count<200:
> if count%3==0:
> answer = answer + count**3
> count = count + 1
>
> print ("Result is: " +str(answer))
>
> Is it all okay?
>
> Regards
> --
> https://mail.python.org/mailman/listinfo/python-list

You should run it to see what results you get.  I am guessing that you
don't know the ultimate answer, but you could run it for a much
smaller number than 200 and check the results by hand.



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if this basic Python script is coded right

2013-10-26 Thread Mark Lawrence

On 26/10/2013 18:36, HC wrote:

I'm doing my first year in university and I need help with this basic 
assignment.

Assignment: Write Python script that prints sum of cubes of numbers between 
0-200 that are multiples of 3. 3^3+6^3+9^3+12^3+198^3=?

My script:
count = 0
answer = 0

while count<200:
 if count%3==0:
 answer = answer + count**3
 count = count + 1

print ("Result is: " +str(answer))

Is it all okay?

Regards



Simplify it by using a for loop with range(count) and you can also write 
answer += count**3.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Check if this basic Python script is coded right

2013-10-26 Thread John Ladasky
HC, you have come straight out and told us honestly that you are seeking help 
with homework.  That is refreshing.  

You should know that people in programming newsgroups generally do not want to 
do your homework for you.  Many of us are willing to teach you HOW to program, 
but that's different than just handing you the answer to a specific question.

Do you know how to CHECK whether the output of your program is correct 
yourself?  Did you run it?  What output did you get?  Did it tell you anything 
useful?  If it did not tell you anything useful, what simple changes might you 
make to tell you something useful?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if this basic Python script is coded right

2013-10-26 Thread MRAB

On 26/10/2013 18:36, HC wrote:

I'm doing my first year in university and I need help with this basic 
assignment.

Assignment: Write Python script that prints sum of cubes of numbers between 
0-200 that are multiples of 3. 3^3+6^3+9^3+12^3+198^3=?

My script:
count = 0
answer = 0

while count<200:
 if count%3==0:
 answer = answer + count**3
 count = count + 1

print ("Result is: " +str(answer))

Is it all okay?


Just one small point: the assignment says that the numbers should be in
the range 0-200, but the loop's condition is count<200 it's excluding
200, so the numbers will actually be in the range 0-199.

However, as 200 isn't a multiple of 3, it won't affect the result, but
in another assignment it might.

(For the record, this is known as an "off-by-one" error.)

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


Re: Printing a drop down menu for a specific field.

2013-10-26 Thread rurpy
On 10/20/2013 05:30 PM, Νίκος Αλεξόπουλος wrote:
> try:
>   cur.execute( '''SELECT host, city, useros, browser, ref, hits, 
> lastvisit FROM visitors WHERE counterID = (SELECT ID FROM counters WHERE 
> url = %s) ORDER BY lastvisit DESC''', page )
>   data = cur.fetchall()
>   
>   for row in data:
>   (host, city, useros, browser, ref, hits, lastvisit) = row
>   lastvisit = lastvisit.strftime('%A %e %b, %H:%M')
>   
>   print( "" )
>   for item in (host, city, useros, browser, ref, hits, lastvisit):
>   print( " %s " % 
> item )
> except pymysql.ProgrammingError as e:
>   print( repr(e) )
> ===
> 
> In the above code i print the record of the mysql table visitors in each 
> row like this:  http://superhost.gr/?show=log&page=index.html
> 
> Now, i wish to write the same thing but when it comes to print the 
> 'lastvisit' field to display it in a  tag so all prior 
> visits for the same host appear in a drop down menu opposed to as i have 
> it now which i only print the datetime of just the latest visit of that 
> host and not all its visit datetimes.

Perhaps something like this is what you are looking for?

> try:
>   cur.execute( '''SELECT host, city, useros, browser, ref, hits, 
> lastvisit FROM visitors WHERE counterID = (SELECT ID FROM counters WHERE 
> url = %s) ORDER BY lastvisit DESC''', page )
>   data = cur.fetchall()
>
newdata = coalesce( data )
for row in newdata:
(host, city, useros, browser, ref, hits, visits) = row
  # Note that 'visits' is now a list of visit times.
print( "" )
for item in (host, city, useros, browser, ref, hits):
print( " %s " % item )
print( "" )
for n, visit in enumerate (visits):
visittime = visit.strftime('%A %e %b, %H:%M')
if n == 0: op_selected = 'selected="selected"'
else: op_selected = ''
print( "%s" % (op_selected, visittime) )
print( "" )
print( "" )

def coalesce (data):
'''Combine multiple data rows differing only in the 'hits' and
'visits' fields into a single row with 'visits' changed into a
list of the multiple visits values, and hits changed into the
sum of the multiple 'hits' values.  Order of rows is preserved
so that rows with most recent visits still come first.'''

newdata = []
seen = {}
for host, city, useros, browser, ref, hits, visit in data:
# Here you have to decide how to group the rows together.
# For example, if you have
#   178-20-236.static.cyta.gr | Europe/Athens | Windows | Explorer 
| Direct Hit | 1 | Παρασκευή 25 Οκτ, 20:48
#   178-20-236.static.cyta.gr | Europe/Athens | Windows | Explorer 
| Direct Hit | 3 | Παρασκευή 25 Οκτ, 20:06
# do you want those as one row on the html page, or two?
# If one, what value do you want to show for 'hits' (Επανάληψη)?
# "1", "3", "4"?
# I'll assume that you want an html row for every unique
# combination of (host, city, useros, browser) and that hits
# should be summed together.
key = host, city, useros, browser, ref
if key not in seen:
newdata.append ([host, city, useros, browser, ref, hits, 
[visit]])
seen[key] = len (newdata) - 1# Save index (for 'newdata') 
of this row.
else:  # This row is a duplicate row with a different visit time.
rowindex = seen[key]
newdata[rowindex][5] += hits
newdata[rowindex][6].append (visit)
return newdata

Several caveats...  
The code above is untested, you'll probably have to fix some errors
but hopefully it is clear enough.
I only read this group intermittently these days so it you respond 
with question about the code, or need more help, it is likely I
will not see your message so don't be surprised if you don't get an
answer.

Hope this is more helpful than the other answers you got.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python on a MacBook Pro (not my machine)

2013-10-26 Thread John Ladasky
Hi folks,

My side job as a Python tutor continues to grow.  In two weeks, I will start 
working with a high-school student who owns a MacBook Pro.  

I have had students with Linux systems (my preference) and Windows systems 
before, but not Macs.  On my first visit, I set up each student's computer with 
Python 3.x, and SciTE for editing.  I would like to do something similar for my 
Mac student, and I want to make sure that it goes smoothly.

My first question is whether Mac OS X ships with Python 2.x, and whether I need 
to be aware of any compatibility issues when I install 3.x.  (It's 2013, and my 
students are new to programming.  I refuse to hitch them to Python 2.)

Second: it doesn't look like I will be able to obtain SciTE for this student.  
SciTE is free for Windows and Linux.  Apparently, it's $42 for Mac OSX?  If I 
recall, SciTE is open-source, so I suppose that I could compile the source 
myself.  But since it is not my computer, and I'm being paid for my time, and I 
haven't done much with Macs (to say nothing of building from source code), I 
don't think that this is appropriate.

I know, we can use IDLE.  I continue to find IDLE clumsy.  Also, there are 
potential issues with event handling which arise when you use IDLE.  I am 
working with an adult professional who is developing a Telnet application, 
which refuses to cooperate with IDLE/Tk.  I had similar issues myself with 
wxPython applications I was writing.  While these issues may not affect a 
beginning student, these experiences have informed my choices.

So, what other free and lightweight editing options do I have for a Mac?  I 
have found a few (fairly old) discussions on comp.lang.python which suggest 
Eric (http://eric-ide.python-projects.org/) and Editra (http://editra.org/).  
Opinions on these and other choices are appreciated.

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


status of new python.org

2013-10-26 Thread Joaquin Abian
Is there any updated roadmap/schedule for the new python.org site ?
It has been in beta mode at http://preview.python.org/ for several months but I 
can not find in there any indication of the progress or the possible date for 
publishing it. Most paragraphs are still with Lore Ipsum.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread Chris Angelico
On Sat, Oct 26, 2013 at 11:15 PM, rusi  wrote:
> tl;dr I think Mark's scoldings in this regard will work if they come not just 
> from him but from any and every one.  They are likely to have a larger 
> subscription if you would agree to change: "Dont use GG!!"
> to
> "Users of GG are requested to read and follow these instructions
> https://wiki.python.org/moin/GoogleGroupsPython "

I would say that "Don't use Google Groups" is absolutely the right
advice, because it penalizes the ultimate cause of the problem. If a
bus company sets timetables that demand the drivers work the
accelerator and brake in binary (one or the other is always flat
down), the advice is not "Don't buy eggs" but "Don't ride that bus
line". Considering how easy it is to use some other way of posting and
reading, there's no reason for the makers of a fundamentally flawed
piece of software to be rewarded with usage.

Anyway, no matter how carefully you fix your own posts, you'll still
run into the one problem you can't fix: that, because of the extremely
poor signal-to-noise ratio from GG, a number of people just won't see
your post.

And trust me. No matter how many times you ask people to read that
wiki page, you'll still get far FAR better results by recommending
Thunderbird or email. I've seen a good number of people go "Oh, my
posts are annoying because of the software I'm using? No probs, I'll
change software to not be annoying", which solves the problem without
the fiddlinesses that the wiki page advocates.

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


Re: Cookie aint retrieving when visiting happens from a backlink.

2013-10-26 Thread Antoon Pardon

Op 25-10-13 17:04, Nick the Gr33k schreef:

Στις 25/10/2013 5:21 μμ, ο/η Mark Lawrence έγραψε:

On 25/10/2013 13:54, Nick the Gr33k wrote:

Στις 25/10/2013 3:35 μμ, ο/η Chris Angelico έγραψε:

On Fri, Oct 25, 2013 at 11:20 PM, Nick the Gr33k
 wrote:

Στις 25/10/2013 3:11 μμ, ο/η Chris Angelico έγραψε:


On Fri, Oct 25, 2013 at 10:46 PM, Nick the Gr33k

wrote:


Can you reproduce this simple problem on your side to see if it
behaves
the
same way as in me?



Like I said at the beginning, no it doesn't. Go forth and wield the
Google.

ChrisA


Answer me in detail an stop pointing me at vague google searchs.


No.

ChrisA


Yes, don't be lazy.



I'll be blunt and to the point.  Fuck off.  Oh, sorry for my lack of
manners, fuck off please.  Now have you finally got the message?



After you please, i insist!


Yes now you insist. But when someone later will point out how you insist
to be helped, you will blatantly deny you do.

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


Re: Cookie (expletive) problem

2013-10-26 Thread Zero Piraeus
:

On Sat, Oct 26, 2013 at 04:27:03PM +0300, Nick the Gr33k wrote:
> [... the same thing, yet again, with added profanity ...]

Stop that right now. You have been told repeatedly:

1. That this is the wrong forum to address your problem.

2. What other avenues to explore to fix it.

3. To stop reposting the same question over and over again.

... and now you're adding expletives to the subject line of a post which
will be read in a workplace environment.

If you can't learn your trade, at least learn some basic respect for
others.

 -[]z.

-- 
Zero Piraeus: coram publico
http://etiol.net/pubkey.asc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Obfuscated factorial

2013-10-26 Thread Gene Heskett
On Saturday 26 October 2013 10:12:33 Steven D'Aprano did opine:

> Just for fun:
> 
> 
> class Numberator:
> def __init__(self, number):
> self.__number = number
> def evaluate(self):
> return self.__number
> 
> class Multiplier:
> def __init__(self, multiplier, multiplicand):
> self.multiplier = multiplier
> self.multiplicand = multiplicand
> def evaluate(self):
> return self.multiplier * self.multiplicand.evaluate()
> 
> class FactorialBuilder:
> def __init__(self, number):
> if not isinstance(number, int):
> raise TypeError
> if number < 0:
> raise ValueError
> self.__number = number
> def build(self):
> multiplicand = Numberator(1)
> for n in range(2, self.__number + 1):
> multiplicand = Multiplier(n, multiplicand)
> return Factorialiser(multiplicand)
> 
> class Factorialiser:
> def __init__(self, evaluatorix):
> self.__evaluatorix = evaluatorix
> def calculate(self):
> return self.__evaluatorix.evaluate()
> 
> for i in range(16):
> print(i, FactorialBuilder(i).build().calculate())
> 
> 
> 
> And the output is:
> 
> 0 1
> 1 1
> 2 2
> 3 6
> 4 24
> 5 120
> 6 720
> 7 5040
> 8 40320
> 9 362880
> 10 3628800
> 11 39916800
> 12 479001600
> 13 6227020800
> 14 87178291200
> 15 1307674368000
> 
Nice, but will it go to 70? :) 
> 
> It goes without saying that this isn't Pythonic :-)


Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)

"Out of register space (ugh)"
-- vi
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie fucking problem

2013-10-26 Thread Antoon Pardon

Op 26-10-13 18:00, Steven D'Aprano schreef:

On Sat, 26 Oct 2013 15:34:23 +0100, Mark Lawrence wrote:


On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


Mark, please resist the urge to bait Nick with insults. As entertaining
as they may be, they don't actually help reduce the problem.


So? I haven't seen any reaction to Nikos reducing the problem. So if
that is your criterium, you should stop reacting yourself and ask
everyone else to stop reacting.

--
Antoon Pardon

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


Re: Cookie fucking problem

2013-10-26 Thread Antoon Pardon

Op 26-10-13 18:19, Mark Lawrence schreef:

On 26/10/2013 17:00, Steven D'Aprano wrote:

On Sat, 26 Oct 2013 15:34:23 +0100, Mark Lawrence wrote:


On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


Mark, please resist the urge to bait Nick with insults. As entertaining
as they may be, they don't actually help reduce the problem.





I promise to stop baiting this complete and utter moron when I observe
that nobody on this group says a single word to him as that's the only
message that he'll understand.  Any word to him from anybody and I
reserve the right to join in.


I fear this strategy is not stable. Just suppose most people follow this
strategy but someone reacts to Nikos anyhow. Now suddenly a lot of
people feel they have the right to join in. And of course these
reactions will feed this feeling.

I understand you feel you don't have to keep silent if others aren't
but I wish your trigger would be less sensitive.

--
Antoon Pardon

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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-26 Thread Peter Cacioppi
Paul Rubin said:

"FYI, there is real though imprecise garbage collection for C.  Web
search for "Boehm garbage collection" should find more info"

Very interesting. This wasn't around the last time I launched a C/C++ project 
from scratch. Thanks for the tip.

I have to admit, off the top of my head I can't quite grok how it could 
possibly work  which means I will learn something from studying it. But not 
right now.

Thanks! Some great CS minds on this forum.


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


Re: Cookie xxxxing problem

2013-10-26 Thread Stephan Vladimir Bugaj
I rarely ever post here.

But I wanted to say that people responding to this Nikos troll makes reading 
this list a nuisance.

You've never ever been successful in convincing him to behave, and it's been 
going on for quite a while now.

I remain subscribed for occasional  interesting new idioms and tips, but always 
have to sift through this nonsense.

And all of you who take the bait are as much a part of the problem as the 
troll. 

Just ignore the guy.

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


Re: Check if this basic Python script is coded right

2013-10-26 Thread Terry Reedy

On 10/26/2013 2:20 PM, MRAB wrote:

On 26/10/2013 18:36, HC wrote:

I'm doing my first year in university and I need help with this basic
assignment.

Assignment: Write Python script that prints sum of cubes of numbers
between 0-200 that are multiples of 3. 3^3+6^3+9^3+12^3+198^3=?

My script:
count = 0
answer = 0

while count<200:
 if count%3==0:
 answer = answer + count**3
 count = count + 1

print ("Result is: " +str(answer))

Is it all okay?


Just one small point: the assignment says that the numbers should be in
the range 0-200, but the loop's condition is count<200 it's excluding
200, so the numbers will actually be in the range 0-199.


'Between 0-200' could well be interpreted to exclude both 0 and 200 and 
to mean 'in 1-190'. Problem posers should be clear about ranges and 
students should be careful to understand the problem given.



However, as 200 isn't a multiple of 3, it won't affect the result, but
in another assignment it might.

(For the record, this is known as an "off-by-one" error.)


Unfortunately common.

--
Terry Jan Reedy

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


Re: Python on a MacBook Pro (not my machine)

2013-10-26 Thread Shao Hong
Hi John,

In my college, we are using Python 3.x to teach and personally I am using a
Mac and it works well so far. But back to development work, I use 2.7x
because of libraries I using.

As for ide, we are using IDLE, we understand it is clumsy but it is the
most basic and since it comes with it, so why not make use of it. But my
personal choice will be Sublime and pyCharm or even vim.




Shao Hong
[email protected]

"Respect needs to be earned, but honour is an attitude of the heart. Not
everyone will earn your respect, but everyone deserves to be shown honour."
- Anonymous


On Sun, Oct 27, 2013 at 3:07 AM, John Ladasky wrote:

> Hi folks,
>
> My side job as a Python tutor continues to grow.  In two weeks, I will
> start working with a high-school student who owns a MacBook Pro.
>
> I have had students with Linux systems (my preference) and Windows systems
> before, but not Macs.  On my first visit, I set up each student's computer
> with Python 3.x, and SciTE for editing.  I would like to do something
> similar for my Mac student, and I want to make sure that it goes smoothly.
>
> My first question is whether Mac OS X ships with Python 2.x, and whether I
> need to be aware of any compatibility issues when I install 3.x.  (It's
> 2013, and my students are new to programming.  I refuse to hitch them to
> Python 2.)
>
> Second: it doesn't look like I will be able to obtain SciTE for this
> student.  SciTE is free for Windows and Linux.  Apparently, it's $42 for
> Mac OSX?  If I recall, SciTE is open-source, so I suppose that I could
> compile the source myself.  But since it is not my computer, and I'm being
> paid for my time, and I haven't done much with Macs (to say nothing of
> building from source code), I don't think that this is appropriate.
>
> I know, we can use IDLE.  I continue to find IDLE clumsy.  Also, there are
> potential issues with event handling which arise when you use IDLE.  I am
> working with an adult professional who is developing a Telnet application,
> which refuses to cooperate with IDLE/Tk.  I had similar issues myself with
> wxPython applications I was writing.  While these issues may not affect a
> beginning student, these experiences have informed my choices.
>
> So, what other free and lightweight editing options do I have for a Mac?
>  I have found a few (fairly old) discussions on comp.lang.python which
> suggest Eric (http://eric-ide.python-projects.org/) and Editra (
> http://editra.org/).  Opinions on these and other choices are appreciated.
>
> Thanks!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


trying to strip out non ascii.. or rather convert non ascii

2013-10-26 Thread bruce
hi..

getting some files via curl, and want to convert them from what i'm
guessing to be unicode.

I'd like to convert a string like this::
Alcántar,
Iliana

to::
Alcantar,
Iliana

where I convert the
" á " to " a"

which appears to be a shift of 128, but I'm not sure how to accomplish this..

I've tested using the different decode/encode functions using
utf-8/ascii with no luck.

I've reviewed stack overflow, as well as a few other sites, but
haven't hit the aha moment.

pointers/comments would be welcome.

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


Re: Check if this basic Python script is coded right

2013-10-26 Thread Terry Reedy

On 10/26/2013 1:36 PM, HC wrote:

I'm doing my first year in university and I need help with this basic 
assignment.

Assignment: Write Python script that prints sum of cubes of numbers between 
0-200 that are multiples of 3. 3^3+6^3+9^3+12^3+198^3=?

My script:
count = 0
answer = 0

while count<200:
 if count%3==0:
 answer = answer + count**3
 count = count + 1

print ("Result is: " +str(answer))

Is it all okay?


Generalize the problem, put the code in a reusable testable function, 
and start with test cases.

--
def sum33(n):
  "Return sum of cubes of multiples of 3 <= n."

for n, sm in ( (0,0), (2,0), (3,27), (4,27), (6,243), ):
  assert sum33(n) == sm

print(sum33(200))
--
This will fail because None != 0. Now add 'return 0' and the first two 
cases pass and then it fails with None != 27. Now change 'return 0' to


  answer = 0
  for i in range(3, n+1, 3):
answer += i*i*i
  return answer

and it will print 131990067, which I presume is correct. Putting your 
code in the body instead, indented, with '200' replaced with 'n+1', and 
with 'return answer' added, gives the same result after passing the same 
tests.


--
Terry Jan Reedy

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


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-26 Thread Peter Cacioppi
Rusi said:


"Users of GG are requested to read and follow these instructions
https://wiki.python.org/moin/GoogleGroupsPython " 

Yes, I read those instructions and found them fairly opaque. If you want to 
instruct "children" (odd that I find myself categorized that way on a CS forum, 
but whatever) then you use pictures.

Seriously, it's not exactly clear what protocol GG users are expected follow to 
make posts hygenic. The standards I've used when creating this sort of content 
is to use screen shots with arrows and circles drawn in. If you're going to 
make an instruction page for some nuanced client feature, spend an extra 10 
minutes and make it fully idiot proof.

With re: the snark ... I am shocked, shocked to find snarky comments on the 
internet. (eyeroll) There was plenty of snark in this joint before I posted, 
good luck policing that. 

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


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-26 Thread MRAB

On 26/10/2013 21:11, bruce wrote:

hi..

getting some files via curl, and want to convert them from what i'm
guessing to be unicode.

I'd like to convert a string like this::
Alcántar,
Iliana

to::
Alcantar,
Iliana

where I convert the
" á " to " a"

which appears to be a shift of 128, but I'm not sure how to accomplish this..

I've tested using the different decode/encode functions using
utf-8/ascii with no luck.

I've reviewed stack overflow, as well as a few other sites, but
haven't hit the aha moment.

pointers/comments would be welcome.


Why do you want to do that?

The short answer is that you should accept that these days you should
be using Unicode, not ASCII.

The longer answer is that you could normalise the Unicode codepoints to
the NFKD form and then discard any codepoints outside the ASCII range:


import unicodedata
t = unicodedata.normalize("NFKD", "Alcántar")
"".join(c for c in t if ord(c) < 0x80)

'Alcantar'

The disadvantage, of course, is that it'll throw away a whole lot of
codepoints that can't be 'converted'.

Have a look at Unidecode:

http://pypi.python.org/pypi/Unidecode

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


Re: Cookie fucking problem

2013-10-26 Thread Mark Lawrence

On 26/10/2013 18:23, Antoon Pardon wrote:

Op 26-10-13 18:19, Mark Lawrence schreef:

On 26/10/2013 17:00, Steven D'Aprano wrote:

On Sat, 26 Oct 2013 15:34:23 +0100, Mark Lawrence wrote:


On 26/10/2013 14:27, Nick the Gr33k wrote:

Buy a sex manual.


Mark, please resist the urge to bait Nick with insults. As entertaining
as they may be, they don't actually help reduce the problem.





I promise to stop baiting this complete and utter moron when I observe
that nobody on this group says a single word to him as that's the only
message that he'll understand.  Any word to him from anybody and I
reserve the right to join in.


I fear this strategy is not stable. Just suppose most people follow this
strategy but someone reacts to Nikos anyhow. Now suddenly a lot of
people feel they have the right to join in. And of course these
reactions will feed this feeling.

I understand you feel you don't have to keep silent if others aren't
but I wish your trigger would be less sensitive.



I wish I didn't have a combination of Asperger Syndrome, Chronic Fatigue 
Syndrome and Clinical Depression but sadly I'm stuck with the lot :(


Regardless of what others (rusi?) said earlier I'll keep my sense of 
humour going, it least that helps me to survive :)


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Python Front-end to GCC

2013-10-26 Thread Mark Janssen
[Getting back to some old comments]

>>> A language specification in BNF is just syntax. It doesn't say anything
>>> about semantics. So how could this be used to produce executable C code
>>> for a program? BNF is used to produce parsers. But a parser isn't
>>> sufficient.
>>
>> A C program is just syntax also.  How does the compiler generate
>> executable machine code?  Extrapolate into a Python front-end to C.
>
> Did you even read the paragraph you quoted above?  The BNF specification
> does NOT completely describe a language, it only defines its syntax.

Computer Science 301 (a.k.a. "educating the python brogrammers who've
been too long using interpreted languages"):

C source ("blah.c") is broken down into a linear sequence of tokens
fed into a parser.  The BNF definition for C takes those tokens/syntax
and produces a lexical graph of the source -- its grammatical form.
This becomes an abstract syntax *tree* because there is a "main"
function (without which I don't believe you can call a language
formally "Turing Complete" because one doesn't know where to begin to
feed the machine (wait for it boom)).  In any case, this *roots*
the abstract lexical graph and forms the basis for compiling into
machine code.

>  So
> if the only thing you knew about C was its BNF, you could certainly not
> write a C compiler.  And neither could anyone else.

Well, now you're confusing everybody, because you're asking, in
essence: "what is the meaning of a symbol to a computer?", and since
there isn't one, then you should wonder: "how are you going to get it
to 'do the right thing?'"  For that, you'll have to take Mark
Janssen's PHIL 444: "Epistemics of Quantity" (not offered from the
internet).

Now, please give credit to all the old-timers who paved the way for
all you to be partying in the easy-land of high-level languages like
Python.  It's them who made the computer SCIENCE.  You guys have been
so spoiled, you're taking it all for granted and confusing people with
all your claptrap about TYPES.  The insane cannot tell that they're
insane.  Remember that.

> Fortunately for the
> C community, the language specification included much more than a BNF
> grammar.  At a minimum, you have to specify both the syntax and the
> semantics.

I will look forward to how you will give a semantic specification for
the C token "{": left bracket.

Apologies will be accepted on the list.

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


Re: status of new python.org

2013-10-26 Thread Mark Lawrence

On 26/10/2013 20:12, Joaquin Abian wrote:

Is there any updated roadmap/schedule for the new python.org site ?
It has been in beta mode at http://preview.python.org/ for several months but I 
can not find in there any indication of the progress or the possible date for 
publishing it. Most paragraphs are still with Lore Ipsum.



I don't know, but I do hope they change the very conspicious print 
statement to a function before it goes live :)  And using input indeed, 
well I never did!!!


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Python Front-end to GCC

2013-10-26 Thread Mark Janssen
> Apologies will be accepted on the list.

BTW, I can't resist pointing out that you guys are like a cup already
full of (black) coffee -- too full to allow the pure water of clarity
to enter.

(cf. Buddhism)   .. (boom)

MarkJanssen
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-26 Thread John Nagle
On 10/25/2013 12:18 PM, Mark Janssen wrote:
>> As for the hex value for Nan who really gives a toss?  The whole point is
>> that you initialise to something that you do not expect to see.  Do you not
>> have a text book that explains this concept?
> 
> No, I don't think there is a textbook that explains such a concept of
> initializing memory to anything but 0 -- UNLESS you're from Stupid
> University.
> 
> Thanks for providing fodder...
> 
> Mark Janssen, Ph.D.
> Tacoma, WA

What a mess of a discussion.

First off, this is mostly a C/C++ issue, not a Python issue,
because Python generally doesn't let you see uninitialized memory.

Second, filling newly allocated memory with an illegal value
is a classic debugging technique.  Visual C/C++ uses it
when you build in debug mode.  Wikipedia has an explanation:

http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Magic_debug_values

Microsoft Visual C++ uses 0xBAADF00D.  In valgrind, there's
a "-malloc-fill" option, and you can specify a hex value.

There's a performance penalty for filling large areas of memory
so it's usually done in debug mode only, and is sometimes causes
programs with bugs to behave differently when built in debug
vs. release mode.

Sigh.

John Nagle





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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-26 Thread Mark Lawrence

On 26/10/2013 20:24, Peter Cacioppi wrote:

Paul Rubin said:

"FYI, there is real though imprecise garbage collection for C.  Web
search for "Boehm garbage collection" should find more info"

Very interesting. This wasn't around the last time I launched a C/C++ project 
from scratch. Thanks for the tip.

I have to admit, off the top of my head I can't quite grok how it could 
possibly work  which means I will learn something from studying it. But not 
right now.

Thanks! Some great CS minds on this forum.




Very true.

Now before I forget I hope you find these links useful.

http://dirtsimple.org/2004/12/python-is-not-java.html
http://dirtsimple.org/2004/12/java-is-not-python-either.html

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Python Front-end to GCC

2013-10-26 Thread Mark Lawrence

On 26/10/2013 22:33, Mark Janssen wrote:

Apologies will be accepted on the list.


BTW, I can't resist pointing out that you guys are like a cup already
full of (black) coffee -- too full to allow the pure water of clarity
to enter.

(cf. Buddhism)   .. (boom)

MarkJanssen
Tacoma, Washington



I took a look at your sourceforge page yesterday.  I found it extremely 
sad that you'd clearly taken so many contaminated batches over so many 
years.  Seriously.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Cookie fucking problem

2013-10-26 Thread Ben Finney
Mark Lawrence  writes:

> I could almost feel sorry for you.  But the more of your time I waste
> the longer it'll take you to get your website working.

Feel free to occupy your time with baiting Nikos. But *do not* do it in
this forum.

-- 
 \   “I love and treasure individuals as I meet them, I loathe and |
  `\ despise the groups they identify with and belong to.” —George |
_o__) Carlin, 2007 |
Ben Finney

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


Re: Cookie fucking problem

2013-10-26 Thread Ben Finney
Mark Lawrence  writes:

> I wish I didn't have a combination of Asperger Syndrome, Chronic
> Fatigue Syndrome and Clinical Depression but sadly I'm stuck with the
> lot :(

I wish you didn't have those. Please don't saddle this forum with the
result.

-- 
 \  “And if I laugh at any mortal thing, / 'Tis that I may not |
  `\   weep.” —“Lord” George Gordon Noel Byron, _Don Juan_ |
_o__)  |
Ben Finney

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


array/list of sockets

2013-10-26 Thread theelder777
Hello all, I am kind of new to python. I am currently trying to make and use a 
list/array of sockets in a program. So I have declared an array as follows:
myCSocks = ['CSock1', 'CSock2', 'CSock3', 'CSock4', 'CSock5']

and I am trying to use my array elements as follows:
myCSocks[i], addr = serverSocket.accept()
 and 
message = myCSocks[i].recv(1024)

I am getting the following error:
Traceback (most recent call last):
  File "./htmlserv_multi.py", line 22, in 
message = myCSocks[i].recv(1024)
AttributeError: 'str' object has no attribute 'recv'


This kind of makes sense to me, it is saying that my array elements are of type 
String and are not sockets. So I understand what my problem is but I do not 
know how to remedy it. I have googled "list of sockets python" but did not find 
anything. Any help will be greatly appreciated. Thank you. 

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


Re: Python Front-end to GCC

2013-10-26 Thread Mark Lawrence

On 26/10/2013 22:25, Mark Janssen wrote:

Please give it a rest Mark, nobody is falling for your pseudo babel.

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: array/list of sockets

2013-10-26 Thread Mark Lawrence

On 26/10/2013 22:41, [email protected] wrote:

Hello all, I am kind of new to python. I am currently trying to make and use a 
list/array of sockets in a program. So I have declared an array as follows:
myCSocks = ['CSock1', 'CSock2', 'CSock3', 'CSock4', 'CSock5']


This is a list of Python strings, not an array, not sockets.



and I am trying to use my array elements as follows:
myCSocks[i], addr = serverSocket.accept()
  and
message = myCSocks[i].recv(1024)

I am getting the following error:
Traceback (most recent call last):
   File "./htmlserv_multi.py", line 22, in 
 message = myCSocks[i].recv(1024)
AttributeError: 'str' object has no attribute 'recv'


This kind of makes sense to me, it is saying that my array elements are of type String 
and are not sockets. So I understand what my problem is but I do not know how to remedy 
it. I have googled "list of sockets python" but did not find anything. Any help 
will be greatly appreciated. Thank you.



See this http://docs.python.org/3/library/socket.html#example

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: array/list of sockets

2013-10-26 Thread Johannes Findeisen
Hi,

On Sat, 26 Oct 2013 14:41:15 -0700 (PDT)
theelder777@ wrote:

> Hello all, I am kind of new to python. I am currently trying to make and use 
> a list/array of sockets in a program. So I have declared an array as follows:
> myCSocks = ['CSock1', 'CSock2', 'CSock3', 'CSock4', 'CSock5']

You actually have added strings to your list. this 'is_a_string.

You need to add the objcts to the list. E.g.: 

myCSocks = [CSock1, CSock2, CSock3, CSock4, CSock5]

Hope this helps.

Regards,
Johannes
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-26 Thread Mark Janssen
> What a mess of a discussion.

I see the big man stepping in to answer for his homies, but while his
explanation satisfies their question of "well why do these magic
values get used then, if what Mark says is true?", it doesn't address
the real confusion:  What is the difference between "script" code
(like Javascript and visual) made for the screen (where such magic
values are utilized) and compiled source (made for the machine)?  And
that is where John, while benevolent, hasn't done the homework of
computer science.   Ask him.

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


Re: Don't use default Google Group client (was re:....)

2013-10-26 Thread Chris Angelico
On Sun, Oct 27, 2013 at 2:05 AM,   wrote:
> The large number of posts here from GG would suggest
> that the readership there is substantial, and the decline in
> "web-1.0" tools (usenet, mailing lists, etc) is additional
> evidence that the number of GG users (who are used to and
> prefer flashier web-based interfaces) may be much greater
> than you would like to think.

That's not a problem. The people who think that Web 2.0 has to
completely supplant everything else are most welcome to spend all day
on Facebook, and try to get their homework help from there. I don't
mind. Meanwhile, the rest of us will continue to use - and to
understand - the lower-level internet protocols that actually work. We
will then go on to develop communication protocols that don't involve
JavaScript in web browsers, that don't have ten-round-trip latency,
and that actually work. SMTP-like or MUD-like protocols seem to be
quite effective, in my experience.

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


Re: array/list of sockets

2013-10-26 Thread theelder777
Thank you for your quick replies. I am trying to implement a very simple 
multithreaded webserver in python. Is using an array of sockets (for different 
clients) the correct way to go?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-26 Thread Steven D'Aprano
On Sat, 26 Oct 2013 16:11:25 -0400, bruce wrote:

> hi..
> 
> getting some files via curl, and want to convert them from what i'm
> guessing to be unicode.
> 
> I'd like to convert a string like this::  href="ShowRatings.jsp?tid=1312168">Alcántar, Iliana
> 
> to::
> Alcantar,
> Iliana
> 
> where I convert the
> " á " to " a"

Why on earth would you want to throw away perfectly good information? 
It's 2013, not 1953, and if you're still unable to cope with languages 
other than English, you need to learn new skills.

(Actually, not even English, since ASCII doesn't even support all the 
characters used in American English, let alone British English. ASCII was 
broken from the day it was invented.)

Start by getting some understanding:

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


Then read this post from just over a week ago:

https://mail.python.org/pipermail/python-list/2013-October/657827.html



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


Re: array/list of sockets

2013-10-26 Thread Chris Angelico
On Sun, Oct 27, 2013 at 9:15 AM,   wrote:
> Thank you for your quick replies. I am trying to implement a very simple 
> multithreaded webserver in python. Is using an array of sockets (for 
> different clients) the correct way to go?

Firstly, before you respond any more, please get off Google Groups.
You are omitting context, which makes threading (topic threading here,
distinct from threads of execution) difficult to follow. Get a news
reader like Thunderbird, or switch to email ([email protected]).
It will be greatly appreciated. :)

As to threading in Python... You don't normally need to maintain a
list of sockets; the easiest way would be to spin off a thread every
time a new connection happens. In pseudo-code:

def connection_thread(sock):
while True:
sock.recv(...)
do stuff with what you got, maybe write to the socket

def acceptloop():
sock = ... however you're creating your listening socket
while True:
newsock = sock.accept()
create new thread, connection_thread, newsock

Each thread needs only care about its one socket.

Now, if you're creating a chat server, where anything that comes in on
one socket goes to all the others, then you'll need to maintain that
list (that's why I said "normally"). In that case, the easiest way
would probably be for connection_thread to register its socket when it
begins, and unregister it when it ends (using try/finally to help).

There are other ways to manage multiple sockets. You could maintain a
list of them all and react any time one is readable/writable, with
select(); I'm not sure how to do that in Python as I've never done so,
but there's a way. With that, you'd simply add sockets to the list
when accept() has something, and remove them when they're closed. But
you said you were threading.

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


Re: array/list of sockets

2013-10-26 Thread Mark Lawrence

On 26/10/2013 23:15, [email protected] wrote:

Thank you for your quick replies. I am trying to implement a very simple 
multithreaded webserver in python. Is using an array of sockets (for different 
clients) the correct way to go?



It's a list :)  And if it works for you, why not, there's nothing at all 
wrong with KISS?


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: array/list of sockets

2013-10-26 Thread theelder777
Thank you all for your time and great replies. I think/hope I have enough info 
to able to implement this simple server.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array/list of sockets

2013-10-26 Thread Mark Lawrence

On 26/10/2013 23:42, [email protected] wrote:

Thank you all for your time and great replies. I think/hope I have enough info 
to able to implement this simple server.



No problem but please take onboard the advice Chris Angelico gave you 
earlier regarding google groups, noting the complete lack of any context 
with your words above :)


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: array/list of sockets

2013-10-26 Thread theelder777

I apologize but I do not understand what you mean by "lack of context." I have 
taken Chris' words into consideration, for my previous post was supposed to be 
my last (I just had to say thank you). This is my first google groups post, so 
I am a total noob. Once again, I apologize for whatever that I may have done. I 
will not post in google groups again : ) 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array/list of sockets

2013-10-26 Thread Chris Angelico
On Sun, Oct 27, 2013 at 10:17 AM,   wrote:
>
> I apologize but I do not understand what you mean by "lack of context." I 
> have taken Chris' words into consideration, for my previous post was supposed 
> to be my last (I just had to say thank you). This is my first google groups 
> post, so I am a total noob. Once again, I apologize for whatever that I may 
> have done. I will not post in google groups again : )

It's conventional, on newsgroups and mailing lists, to quote a piece
of the previous post to show what you're replying to. That's called
context. Google Groups makes this difficult and ugly, which is why we
recommend not using it. There are other interfaces to the same
newsgroup, which do not have this problem; Thunderbird is a
well-recommended one, and you can also subscribe to
[email protected] by going to
https://mail.python.org/mailman/listinfo/python-list - it's the same
content, viewed as emails.

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


Re: array/list of sockets

2013-10-26 Thread mm0fmf

On 27/10/2013 00:17, [email protected] wrote:


I apologize but I do not understand what you mean by "lack of context." I have 
taken Chris' words into consideration, for my previous post was supposed to be my last (I 
just had to say thank you). This is my first google groups post, so I am a total noob. 
Once again, I apologize for whatever that I may have done. I will not post in google 
groups again : )



What is meant by lack of context is that your post only contains your 
words. It does not contain any words from the message(s) you are 
replying to. i.e. there is no context for your reply.


If you look at this message you'll see a line saying who said the quoted 
text followed by the quoted text. Then you see my reply. With that 
context, hopefully, my reply makes sense. Someone should be able to 
understand what the reply means as they have the context for the reply 
all in this message.


Andy

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


Re: Printing a drop down menu for a specific field.

2013-10-26 Thread Nick the Gr33k

Στις 26/10/2013 9:33 μμ, ο/η [email protected] έγραψε:

On 10/20/2013 05:30 PM, Νίκος Αλεξόπουλος wrote:

try:
cur.execute( '''SELECT host, city, useros, browser, ref, hits,
lastvisit FROM visitors WHERE counterID = (SELECT ID FROM counters WHERE
url = %s) ORDER BY lastvisit DESC''', page )
data = cur.fetchall()

for row in data:
(host, city, useros, browser, ref, hits, lastvisit) = row
lastvisit = lastvisit.strftime('%A %e %b, %H:%M')

print( "" )
for item in (host, city, useros, browser, ref, hits, lastvisit):
print( " %s " % 
item )
except pymysql.ProgrammingError as e:
print( repr(e) )
===

In the above code i print the record of the mysql table visitors in each
row like this:  http://superhost.gr/?show=log&page=index.html

Now, i wish to write the same thing but when it comes to print the
'lastvisit' field to display it in a  tag so all prior
visits for the same host appear in a drop down menu opposed to as i have
it now which i only print the datetime of just the latest visit of that
host and not all its visit datetimes.


Perhaps something like this is what you are looking for?


try:
cur.execute( '''SELECT host, city, useros, browser, ref, hits,
lastvisit FROM visitors WHERE counterID = (SELECT ID FROM counters WHERE
url = %s) ORDER BY lastvisit DESC''', page )
data = cur.fetchall()


 newdata = coalesce( data )
 for row in newdata:
 (host, city, useros, browser, ref, hits, visits) = row
   # Note that 'visits' is now a list of visit times.
 print( "" )
 for item in (host, city, useros, browser, ref, hits):
 print( " %s " % item )
 print( "" )
 for n, visit in enumerate (visits):
 visittime = visit.strftime('%A %e %b, %H:%M')
 if n == 0: op_selected = 'selected="selected"'
 else: op_selected = ''
 print( "%s" % (op_selected, visittime) )
 print( "" )
 print( "" )

 def coalesce (data):
 '''Combine multiple data rows differing only in the 'hits' and
 'visits' fields into a single row with 'visits' changed into a
 list of the multiple visits values, and hits changed into the
 sum of the multiple 'hits' values.  Order of rows is preserved
 so that rows with most recent visits still come first.'''

 newdata = []
 seen = {}
 for host, city, useros, browser, ref, hits, visit in data:
 # Here you have to decide how to group the rows together.
 # For example, if you have
 #   178-20-236.static.cyta.gr | Europe/Athens | Windows | Explorer 
| Direct Hit | 1 | Παρασκευή 25 Οκτ, 20:48
 #   178-20-236.static.cyta.gr | Europe/Athens | Windows | Explorer 
| Direct Hit | 3 | Παρασκευή 25 Οκτ, 20:06
 # do you want those as one row on the html page, or two?
 # If one, what value do you want to show for 'hits' (Επανάληψη)?
 # "1", "3", "4"?
 # I'll assume that you want an html row for every unique
 # combination of (host, city, useros, browser) and that hits
 # should be summed together.
 key = host, city, useros, browser, ref
 if key not in seen:
 newdata.append ([host, city, useros, browser, ref, hits, 
[visit]])
 seen[key] = len (newdata) - 1# Save index (for 'newdata') 
of this row.
 else:  # This row is a duplicate row with a different visit time.
 rowindex = seen[key]
 newdata[rowindex][5] += hits
 newdata[rowindex][6].append (visit)
 return newdata

Several caveats...
The code above is untested, you'll probably have to fix some errors
but hopefully it is clear enough.
I only read this group intermittently these days so it you respond
with question about the code, or need more help, it is likely I
will not see your message so don't be surprised if you don't get an
answer.

Hope this is more helpful than the other answers you got.


Thank you very much Rurpy, i appreciate your help very much.
Even of you havent tested it your code runs flawlessly.

Only 1 side effect.
If visitor comes from a referrer link then the visit[] list doesn't not 
add its timestamp into it.


It only adds it in case of a direct hit when there is no referer present.






--
What is now proved was at first only imagined! & WebHost

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


Re: array/list of sockets

2013-10-26 Thread Mark Lawrence

On 27/10/2013 00:17, [email protected] wrote:


I apologize but I do not understand what you mean by "lack of context." I have 
taken Chris' words into consideration, for my previous post was supposed to be my last (I 
just had to say thank you). This is my first google groups post, so I am a total noob. 
Once again, I apologize for whatever that I may have done. I will not post in google 
groups again : )



That's okay, everybody has to start somewhere :)

A definition from http://www.thefreedictionary.com/context "The part of 
a text or statement that surrounds a particular word or passage and 
determines its meaning".  So lack of context means the surrounding part 
is missing, which applies to your words above as nobody knows at a 
glance to whom or to what you're replying.  Clear I hope?


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Printing a drop down menu for a specific field.

2013-10-26 Thread Nick the Gr33k

Στις 27/10/2013 2:31 πμ, ο/η Nick the Gr33k έγραψε:

Στις 26/10/2013 9:33 μμ, ο/η [email protected] έγραψε:

On 10/20/2013 05:30 PM, Νίκος Αλεξόπουλος wrote:

try:
cur.execute( '''SELECT host, city, useros, browser, ref, hits,
lastvisit FROM visitors WHERE counterID = (SELECT ID FROM counters WHERE
url = %s) ORDER BY lastvisit DESC''', page )
data = cur.fetchall()

for row in data:
(host, city, useros, browser, ref, hits, lastvisit) = row
lastvisit = lastvisit.strftime('%A %e %b, %H:%M')

print( "" )
for item in (host, city, useros, browser, ref, hits, lastvisit):
print( " %s " % item )
except pymysql.ProgrammingError as e:
print( repr(e) )
===

In the above code i print the record of the mysql table visitors in each
row like this:  http://superhost.gr/?show=log&page=index.html

Now, i wish to write the same thing but when it comes to print the
'lastvisit' field to display it in a  tag so all prior
visits for the same host appear in a drop down menu opposed to as i have
it now which i only print the datetime of just the latest visit of that
host and not all its visit datetimes.


Perhaps something like this is what you are looking for?


try:
cur.execute( '''SELECT host, city, useros, browser, ref, hits,
lastvisit FROM visitors WHERE counterID = (SELECT ID FROM counters WHERE
url = %s) ORDER BY lastvisit DESC''', page )
data = cur.fetchall()


 newdata = coalesce( data )
 for row in newdata:
 (host, city, useros, browser, ref, hits, visits) = row
   # Note that 'visits' is now a list of visit times.
 print( "" )
 for item in (host, city, useros, browser, ref, hits):
 print( " %s " %
item )
 print( "" )
 for n, visit in enumerate (visits):
 visittime = visit.strftime('%A %e %b, %H:%M')
 if n == 0: op_selected = 'selected="selected"'
 else: op_selected = ''
 print( "%s" % (op_selected,
visittime) )
 print( "" )
 print( "" )

 def coalesce (data):
 '''Combine multiple data rows differing only in the 'hits' and
 'visits' fields into a single row with 'visits' changed into a
 list of the multiple visits values, and hits changed into the
 sum of the multiple 'hits' values.  Order of rows is preserved
 so that rows with most recent visits still come first.'''

 newdata = []
 seen = {}
 for host, city, useros, browser, ref, hits, visit in data:
 # Here you have to decide how to group the rows together.
 # For example, if you have
 #   178-20-236.static.cyta.gr | Europe/Athens | Windows |
Explorer | Direct Hit | 1 | Παρασκευή 25 Οκτ, 20:48
 #   178-20-236.static.cyta.gr | Europe/Athens | Windows |
Explorer | Direct Hit | 3 | Παρασκευή 25 Οκτ, 20:06
 # do you want those as one row on the html page, or two?
 # If one, what value do you want to show for 'hits'
(Επανάληψη)?
 # "1", "3", "4"?
 # I'll assume that you want an html row for every unique
 # combination of (host, city, useros, browser) and that hits
 # should be summed together.
 key = host, city, useros, browser, ref
 if key not in seen:
 newdata.append ([host, city, useros, browser, ref,
hits, [visit]])
 seen[key] = len (newdata) - 1# Save index (for
'newdata') of this row.
 else:  # This row is a duplicate row with a different
visit time.
 rowindex = seen[key]
 newdata[rowindex][5] += hits
 newdata[rowindex][6].append (visit)
 return newdata

Several caveats...
The code above is untested, you'll probably have to fix some errors
but hopefully it is clear enough.
I only read this group intermittently these days so it you respond
with question about the code, or need more help, it is likely I
will not see your message so don't be surprised if you don't get an
answer.

Hope this is more helpful than the other answers you got.


Thank you very much Rurpy, i appreciate your help very much.
Even of you havent tested it your code runs flawlessly.

Only 1 side effect.
If visitor comes from a referrer link then the visit[] list doesn't not
add its timestamp into it.

It only adds it in case of a direct hit when there is no referer present.







Ah foun it had to change in you code this line:
key = host, city, useros, browser, ref

to this line:

key = host, city, useros, browser

so 'ref' wouldnt be calculated in the unique combination key.

I'am still trying to understand the logic of your code and trying to 
create a history list column for the 'referrers'


I dont know how to write it though to produce the sam

Re: array/list of sockets

2013-10-26 Thread theelder777
On Saturday, October 26, 2013 4:36:04 PM UTC-7, Mark Lawrence wrote:

> That's okay, everybody has to start somewhere :)
> 
> 
> 
> A definition from http://www.thefreedictionary.com/context "The part of 
> 
> a text or statement that surrounds a particular word or passage and 
> 
> determines its meaning".  So lack of context means the surrounding part 
> 
> is missing, which applies to your words above as nobody knows at a 
> 
> glance to whom or to what you're replying.  Clear I hope?
> 
> 
> 
> -- 
> 
> Python is the second best programming language in the world.
> 
> But the best has yet to be invented.  Christian Tismer
> 
> 
> 
> Mark Lawrence

Yes, crystal clear. Thank you. Since I am writing this post, I have one final 
question. I got my code to work for a multithreaded web server, how do I test 
if it can handle multiple threads? 

Also as a side note, I have subscribed to the python mailing list but have no 
idea how to use it. Thank you everyone for being patient.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array/list of sockets

2013-10-26 Thread Chris Angelico
On Sun, Oct 27, 2013 at 10:56 AM,   wrote:
> Yes, crystal clear. Thank you. Since I am writing this post, I have one final 
> question. I got my code to work for a multithreaded web server, how do I test 
> if it can handle multiple threads?

Easy! Just make sure the threads take a good bit of time - add calls
to time.sleep() if necessary - and then start multiple clients at the
same time.

> Also as a side note, I have subscribed to the python mailing list but have no 
> idea how to use it. Thank you everyone for being patient.

You should see this post of mine in your emails. When you do, just
reply (and make sure you're sending to [email protected]);
everything else should work.

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


Re: Printing a drop down menu for a specific field.

2013-10-26 Thread Nick the Gr33k

Στις 27/10/2013 2:52 πμ, ο/η Nick the Gr33k έγραψε:

Ah foun it had to change in you code this line:
 key = host, city, useros, browser, ref

to this line:

 key = host, city, useros, browser

so 'ref' wouldnt be calculated in the unique combination key.

I'am still trying to understand the logic of your code and trying to
create a history list column for the 'referrers'

I dont know how to write it though to produce the sam


Iam trying.

Ah foun it had to change in you code this line:
key = host, city, useros, browser, ref

to this line:

key = host, city, useros, browser

so 'ref' wouldnt be calculated in the unique combination key.

I'am still trying to understand the logic of your code and trying to 
create a history list column for the 'referrers'


I dont know how to write it though to produce the same output for referrers.

The bast i came up with is:

[code]
def coalesce( data ):
newdata = []
seen = {}
for host, city, useros, browser, ref, hits, visit in data:
# Here i have to decide how to group the rows together.
			# I want an html row for every unique combination of (host, city, 
useros, browser) and that hits should be summed together.

key = host, city, useros, browser
if key not in seen:
newdata.append( [host, city, useros, browser, 
[ref], hits, [visit]] )
seen[key] = len( newdata ) - 1		# Save index (for 'newdata') of this 
row.

else:   # This row is a duplicate row with a 
different visit time.
rowindex = seen[key]
newdata[rowindex][4].append( ref )
newdata[rowindex][5] += hits
newdata[rowindex][6].append( visit )
return newdata


	cur.execute( '''SELECT host, city, useros, browser, ref, hits, 
lastvisit FROM visitors
	WHERE counterID = (SELECT ID FROM counters WHERE url = %s) ORDER BY 
lastvisit DESC''', page )

data = cur.fetchall()


newdata = coalesce( data )
for row in newdata:
(host, city, useros, browser, refs, hits, visits) = row
# Note that 'ref' & 'visits' are now lists of visit times.

print( "" )
for item in (host, city, useros, browser):
print( " %s " % 
item )

print( "" )
for n, ref in enumerate( refs ):
if n == 0:
op_selected = 'selected="selected"'
else:
op_selected = ''
print( "%s" % (op_selected, ref) )
print( "" )

for item in (hits):
print( " %s " % 
item )

print( "" )
for n, visit in enumerate( visits ):
visittime = visit.strftime('%A %e %b, %H:%M')
if n == 0:
op_selected = 'selected="selected"'
else:
op_selected = ''
print( "%s" % (op_selected, 
visittime) )
print( "" )

print( "" )
[/code]

But this doesnt work correctly for refs and also doenst not print for 
some reason the hits and visit colums.

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


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-26 Thread Roy Smith
In article ,
 Dennis Lee Bieber  wrote:

> Compared to Baudot, both ASCII and EBCDIC were probably considered
> wondrous.

Wonderous, indeed.  Why would anybody ever need more than one case of 
the alphabet?  It's almost as absurd as somebody wanting to put funny 
little marks on top of their vowels.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie aint retrieving when visiting happens from a backlink.

2013-10-26 Thread Piet van Oostrum
Νίκος Αλεξόπουλος  writes:

> There is no set of cookie returned back when visitor comes from a referer.
>
> Isn't this strange?
> No matter if you visit a webpage as a direct hit or via a referer the
> cookie on the visitor's browser should have been present.
>
> But it can only can be found and retrieved as a direct hit and _not_
> from a referrer backlink.

What is happening is that the page comes from the browser cache when you do a 
back link (back button in your browser). So the request doesn't go to your 
server. I checked this by switching off my internet connection and then trying 
both the back button and entering the URL in the address bar. So it has nothing 
to do with referrer, I think.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: status of new python.org

2013-10-26 Thread Chris Angelico
On Sun, Oct 27, 2013 at 8:26 AM, Mark Lawrence  wrote:
> On 26/10/2013 20:12, Joaquin Abian wrote:
>>
>> Is there any updated roadmap/schedule for the new python.org site ?
>> It has been in beta mode at http://preview.python.org/ for several months
>> but I can not find in there any indication of the progress or the possible
>> date for publishing it. Most paragraphs are still with Lore Ipsum.
>>
>
> I don't know, but I do hope they change the very conspicious print statement
> to a function before it goes live :)  And using input indeed, well I never
> did!!!

There's nothing wrong with using input(), as the examples are clearly
meant to be Python 3 (see the division one, for instance). The other
examples use print as a function - see the Fibonacci one, which uses
end= to suppress the newline - so it's just a bug in the first one,
omitting the parens.

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


Re: Cookie aint retrieving when visiting happens from a backlink.

2013-10-26 Thread Roy Smith
In article ,
 Piet van Oostrum  wrote:

> ÉΪίκος Αλεξόπουλος  writes:
> 
> > There is no set of cookie returned back when visitor comes from a referer.
> >
> > Isn't this strange?
> > No matter if you visit a webpage as a direct hit or via a referer the
> > cookie on the visitor's browser should have been present.
> >
> > But it can only can be found and retrieved as a direct hit and _not_
> > from a referrer backlink.
> 
> What is happening is that the page comes from the browser cache when you do a 
> back link (back button in your browser). So the request doesn't go to your 
> server. I checked this by switching off my internet connection and then 
> trying both the back button and entering the URL in the address bar. So it 
> has nothing to do with referrer, I think.

Unclear what this has to do with Python, but here's a couple of hints 
for debugging / exploring these kinds of issues.

1) Use a command-line tool such as curl to issue the request and see 
exactly what headers are send and come back.

2) If you want to do this inside a browser, use something like Chrome's 
Developer Tools.  In Chrome on the Mac, Command-Option-I will get you 
the tools screen, then click the network tab and send your request.  
It'll capture everything and you can drill down to see all the details.  
Any decent browser should have something similar (possibly as an add-on 
extension).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-26 Thread Tim Chase
On 2013-10-26 22:24, Steven D'Aprano wrote:
> Why on earth would you want to throw away perfectly good
> information? 

The main reason I've needed to do it in the past is for normalization
of search queries.  When a user wants to find something containing
"pingüino", I want to have those results come back even if they type
"pinguino" in the search box.

For the same reason searches are often normalized to ignore case.
The difference between "Polish" and "polish" is visually just
capitalization, but most folks don't think twice about

  if term.upper() in datum.upper():
it_matches()

I'd be just as happy if Python provided a "sloppy string compare"
that ignored case, diacritical marks, and the like.

  unicode_haystack1 = u"pingüino"
  unicode_haystack2 = u"¡Miré un pingüino!"
  needle = u"pinguino"
  if unicode_haystack1.sloppy_equals(needle):
it_matches()
  if unicode_haystack2.sloppy_contains(needle):
it_contains()

As a matter of fact, I'd even be happier if Python did the heavy
lifting, since I wouldn't have to think about whether I want my code
to force upper-vs-lower for the comparison. :-)

-tkc






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


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-26 Thread rusi
On Sunday, October 27, 2013 2:07:53 AM UTC+5:30, Peter Cacioppi wrote:
> Rusi said:
> 
> "Users of GG are requested to read and follow these instructions
> https://wiki.python.org/moin/GoogleGroupsPython " 
> 
> 
> Seriously, it's not exactly clear what protocol GG users are expected follow 
> to make posts hygenic.

Yes... that page is longer and more confusing than necessary.
1. The double-posting bit is unnecessary -- not been happening after the 'new' 
GG.
2. The missing attributions problem is new and needs to be added
3. The main message of that page that needs to be noted is
- to remove extra spurious lines
- to NOT top-post

> The standards I've used when creating this sort of 
> content is to use screen shots with arrows and circles drawn in. If you're 
> going to make an instruction page for some nuanced client feature, spend an 
> extra 10 minutes and make it fully idiot proof.

Please do!
If I were in charge I would say "Patches welcome!"
Who is the 'you' you think you are addressing?

> 
> With re: the snark ... I am shocked, shocked to find snarky comments on the 
> internet. (eyeroll) There was plenty of snark in this joint before I posted, 
> good luck policing that.

Not my complaint: idiocy was my complaint
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-26 Thread Roy Smith
In article ,
 Tim Chase  wrote:

> I'd be just as happy if Python provided a "sloppy string compare"
> that ignored case, diacritical marks, and the like.

The problem with putting fuzzy matching in the core language is that 
there is no general agreement on how it's supposed to work.

There are, however, third-party libraries which do fuzzy matching.  One 
popular one is jellyfish (https://pypi.python.org/pypi/jellyfish/0.1.2).  
Don't expect you can just download and use it right out of the box, 
however. You'll need to do a little thinking about which of the several 
algorithms it includes makes sense for your application.

So, for example, you probably expect U+004 (Latin Capital letter N) to 
match U+006 (Latin Small Letter N).  But, what about these (all cribbed 
from Wikipedia):

U+00D1   Ñ Ñ  Ñ Latin Capital letter N with tilde
U+00F1   ñ ñ  ñ Latin Small Letter N with tilde
U+0143   C  Ń  Latin Capital Letter N with acute
U+0144   D  ń  Latin Small Letter N with acute
U+0145   E  Ņ  Latin Capital Letter N with cedilla
U+0146   F  ņ  Latin Small Letter N with cedilla
U+0147   G  Ň  Latin Capital Letter N with caron
U+0148   H  ň  Latin Small Letter N with caron
U+0149   I  ʼn  Latin Small Letter N preceded by apostrophe[1]
U+014A   J  Ŋ  Latin Capital Letter Eng
U+014B   K  ŋ  Latin Small Letter Eng
U+019D   #413;   Latin Capital Letter N with left hook
U+019E   #414;   Latin Small Letter N with long right leg
U+01CA   #458;   Latin Capital Letter NJ
U+01CB   #459;   Latin Capital Letter N with Small Letter J
U+01CC   #460;   Latin Small Letter NJ
U+0235   #565;   Latin Small Letter N with curl

I can't even begin to guess if they should match for your application.
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   >