Re: New tutorials

2012-12-03 Thread Jean-Michel Pichavant
- Original Message -
> Hi everyone, I'm making a series of python tutorials and I've just
> finished the introductory part: http://lightbird.net/larks/intro.html
> 
> Feedback is appreciated.. - mitya
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

While referencing the python tutorial, you should state how your tutorial 
complement the already existing one, possibly which issues you're trying to 
fix, or how different your approach is.

Cheers,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setup.py Choosing Older Compiler On Windows

2012-12-03 Thread Ami Tavory
From: Irmen de Jong 
>> To: python-list@python.org
>> Cc:
>> Date: Mon, 03 Dec 2012 01:10:23 +0100
>> Subject: Re: setup.py Choosing Older Compiler On Windows
>> On 2-12-2012 22:06, Dave Angel wrote:
>> > On 12/02/2012 09:34 AM, Ami Tavory wrote:
>> >>   Hello,
>> >>
>> >>   I'm porting a C++ extension module to a Windows machine >> that has
both VC8
>> >> and VC10 installed. Unfortunately, `setup.py build` tries to build >>
using
>> >> VC8, which fails (the extension uses C++ standard libraries >> that
VC  didn't
>> >> used to have). Is there a way to get setup.py to use VC10 >>
(preferably
>> >> externally, without modifying the script)?
>> >>
>> >>
>> >
>> > I haven't had to do Windows C++ development for many years, >> but
there
>> > used to be a vcvars.bat  in each compiler installation, and you >> run
the
>> > one corresponding to the compiler & libraries you want.
>>
>>
>> Forcing it to use a different compiler than the one that was used to >>
build Python
>> itself, may very well lead to a non-working extension module.
>>
>> Irmen

  Dave, Irmen,

  Many thanks for your answers - much appreciated!

  Got cvcars.bat to work in the sense that calling the compiler from the
command line resulted in the newer one being called, but setup.py for some
reason persisted in calling the older one. So due to Irmen's concern, this,
and other issues, I just hacked away the C++11 stuff and used the old
compiler.

  Many thanks,

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


Re: Is it bad style to override the built-in function `type`?

2012-12-03 Thread Michael Herrmann
Hi Rusi, 

> Im entering this thread late (was off mail for a week), so pardon me
> if someone has already said this -- but have you looked at the
> difference between internal and external dsls:
> http://martinfowler.com/bliki/DomainSpecificLanguage.html (and links
> therein) ?
> Roughly speaking if what you are making is an external dsl, then its
> not really python (it may be python-inspired but thats not really
> germane) and so reusing python lexemes/structures etc in ways not
> exactly consistent with python usage should be no issue
> 
> If its an internal DSL, you are headed for causing/suffering grief.
> 
> I looked at your site [yes it looked almost interesting -- if only it
> ran on linux :-( ] and I cant really decide whether to classify it as
> external or internal

We want to capitalize on all of Python's advantages (tool/IDE support, 
available libraries etc) and are thus strictly offering an internal DSL (see 
http://www.getautoma.com/features/python_integration). As you pointed out, 
that's why it's important to stay consistent with Python's conventions. 

I agree it'd be nice to have Automa run on Linux, but unfortunately that's 
still a long time away...

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


Re: Python Noob Question.

2012-12-03 Thread Owatch
On Sunday, December 2, 2012 11:44:05 PM UTC+2, Steven D'Aprano wrote:
> On Sun, 02 Dec 2012 12:33:58 -0800, Owatch wrote:
> 
> 
> 
> > Sorry, but I was redirected here via a thread on another forum
> 
> > concerning where to find help for Python. (Python-forums.org not working
> 
> > for me)
> 
> > 
> 
> > I wanted to ask if there was any way I could write a simple Python
> 
> > Temperature program. Where essentially it somehow (Now sure how, I'm a
> 
> > noob remember) read temps off of windows (Providing windows records cpu
> 
> > temps) from their program and then rang an alarm if temperatures
> 
> > exceeded a certain value.
> 
> > 
> 
> > I can write the part about the alarm going off. But I have no idea how
> 
> > to have it stream or update values it would grab from that program
> 
> > (whatever it might be).
> 
> > 
> 
> > Could you please help, or tell me if its possible. Thanks, Owatch.
> 
> 
> 
> Yes, it's possible, but if you have no idea which program you want to 
> 
> read temperature data from, what makes you think we would have any better 
> 
> idea? This is a Python forum, not a "Windows programs that give 
> 
> temperature data" forum.
> 
> 
> 
> I recommend you start by doing some research into how to read the 
> 
> temperature data, including the name of the program. Once you have that, 
> 
> come back to us for help in using Python.
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Sorry if I didn't specify what program. I was thinking of using Core Temp 1.0.
Their website is here: http://www.alcpu.com/CoreTemp/

Or using CPUz. 

If I've got to choose than I'll take Core Temp 1.0

Is this enough information? If you need to know anything else just say so!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List problem

2012-12-03 Thread Neil Cerutti
On 2012-12-02, Thomas Bach  wrote:
> On Sun, Dec 02, 2012 at 04:16:01PM +0100, Lutz Horn wrote:
>> 
>> len([x for x in l if x[1] == 'VBD'])
>> 
>
> Another way is
>
> sum(1 for x in l if x[1] == 'VBD')
>
> which saves the list creation.

To also index them:

vbdix = [i for i, a in emumerate(l) if a[1] == 'VBD']
vbdno = len(indices)

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


Re: Python Noob Question.

2012-12-03 Thread Alexander Blinne
Hello,

by having a quick look at their website i found a plugin for CoreTemp
which acts as a server and can be asked for status information of the
cpu. Now your task is really simple: write a little function or class
that opens a network socket, connects to that plugin und asks it for the
information you require. You just need to find out what network protocol
this plugin uses to communicate. If it is no standard protocol for which
a higher level module is present (xmlrpc or something), see
http://docs.python.org/3/library/socket.html for low level sockets.

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


Re: New tutorials

2012-12-03 Thread Mitya Sirenef

While referencing the python  tutorial, you should state how your

> tutorial complement the already existing one, possibly which issues
> you're trying to fix, or how different your approach is.

> Cheers,

> JM


Thanks for the feedback, I've added the following line to the Intro
section:

My guide will mostly use short, simple games to teach Python and 
Programming in general.



This will also be easy to see just by looking at the listing in the
index once I start adding sections.. the first one coming up!

 - mitya

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


Re: New tutorials

2012-12-03 Thread Mitya Sirenef

On 12/02/2012 09:54 AM, Mitya Sirenef wrote:
Hi everyone, I'm making a series of python tutorials and I've just 
finished the introductory part: http://lightbird.net/larks/intro.html



I've just uploaded a new section -- a tictactoe game:




I've also updated the Intro to state that Python version 3.2+ is required.

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


Re: List problem

2012-12-03 Thread John Gordon
In <8c0a3ea9-2560-47eb-a9c7-3770e41fe...@googlegroups.com> 
subhabangal...@gmail.com writes:

> Dear Group,

> I have a list of the following pattern,

> [("''", "''"), ('Eastern', 'NNP'), ('Army', 'NNP'), ('Commander', 'NNP'), (=
> 'Lt', 'NNP'), ('Gen', 'NNP'), ('Dalbir', 'NNP'), ('Singh', 'NNP'), ('Suhag'=
> , 'NNP'), ('briefed', 'VBD'), ('the', 'DT'), ('Army', 'NNP'), ('chief', 'NN=
> '), ('on', 'IN'), ('the', 'DT'), ('operational', 'JJ'), ('preparedness', 'N=
> N'), ('and', 'CC'), ('the', 'DT'), ('security', 'NN'), ('scenario', 'NN'), =
> ('in', 'IN'), ('the', 'DT'), ('eastern', 'NN'), ('region', 'NN'), (',', ','=
> ), ("''", "''"), ('defence', 'NN'), ('spokesperson', 'NN'), ('Group', 'NNP'=
> ), ('Capt', 'NNP'), ('T', 'NNP'), ('K', 'NNP'), ('Singha', 'NNP'), ('said',=
>  'VBD'), ('here', 'RB')]

> Now, as we see it has multiple VBD elements.
> I want to recognize,count and index them all.

That depends on exactly what you mean by 'reorganize' and 'index'.  But
here's a start:

items = [("''", "''"), ('Eastern', 'NNP'), ('Army', 'NNP'),
('Commander', 'NNP'), ('Lt', 'NNP'), ('Gen', 'NNP'),
('Dalbir', 'NNP'), ('Singh', 'NNP'), ('Suhag' , 'NNP'),
('briefed', 'VBD'), ('the', 'DT'), ('Army', 'NNP'),
('chief', 'NN'), ('on', 'IN'), ('the', 'DT'),
('operational', 'JJ'), ('preparedness', 'NN'), ('and', 'CC'),
('the', 'DT'), ('security', 'NN'), ('scenario', 'NN'),
('in', 'IN'), ('the', 'DT'), ('eastern', 'NN'), ('region', 'NN'),
(',', ','), ("''", "''"), ('defence', 'NN'),
('spokesperson', 'NN'), ('Group', 'NNP'), ('Capt', 'NNP'),
('T', 'NNP'), ('K', 'NNP'), ('Singha', 'NNP'), ('said', 'VBD'),
('here', 'RB')]

vbds = [item[0] for item in items if item[1] == 'VBD']

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


Puzzling error msg.

2012-12-03 Thread wrw
So far in my experience with Python, it's error messages have been clear, 
concise, and quite good at fingering my errors.  However, the message below has 
me stumped.  The routine in question has been running for weeks with no 
problems, then yesterday I got the following:

Traceback (most recent call last):
  File "./Connection_Monitor.py", line 146, in 
Google_up, Google_summary, Google_RTT, Google_stddev = 
Google.connection_test()
  File 
"/Users/wrw/Dev/Python/Connection_Monitor/Version2.2/WorkingCopy/network.py", 
line 101, in connection_test
#
IndexError: list index out of range


The routine is pasted in below:

def connection_test(self):
self.network_up = True
self.error = None
ping_result = subprocess.Popen(['ping', '-qc6', self.target_IP], stderr 
= subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0]
found_0 = '0 packets received' in ping_result
found_1 = '1 packets received' in ping_result
if found_0 == True or found_1 == True:
self.network_up = False
self.ping_summary = 'No route to host'
self.ping_RTT = 'NA'
self.ping_stddev = 'NA'
return self.network_up, self.ping_summary, self.ping_RTT, 
self.ping_stddev
#
That particular command line generates 6 ping packets in quiet mode (summary 
only) and the amount of text returned, even when the ping fails is minimal.
My puzzle two-fold.  First: how could that code generate an "index our of 
range" error, and second: line 101 (the one fingered by the error message) is 
the line following the return statement, the one that contains the # character. 
 I've seen that sort of line slippage when I forgot a ":", but that doesn't 
seem to be the case here.

Python 2.7.3 from Python.org, running on Mac OS-X 10.8.2.

For what it is worth, the definitions of the rest of the class variables follow 
(pretty simple minded):

def __init__(self, target_name):
lan_status = ''
wan_status = ''
path_status = ''
ping_summary = ''
ping_RTT = ''
ping_stddev = ''
target_error = ''
network_up = True
target_error, initial_route, hop_count, target_IP = 
find_initial_route(target_name)
 
self.target_error = target_error
self.initial_route = initial_route
self.hop_count = hop_count
self.gateway = initial_route[0]
self.target_name = target_name
self.target_IP = target_IP
self.hop_count = hop_count
self.lan_status = lan_status
self.wan_status = wan_status
self.path_status = path_status
self.network_up = network_up
self.ping_summary = ping_summary
self.ping_RTT = ping_RTT
self.ping_stddev = ping_stddev

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


Immediate Interview // Direct Client // QNXT Configuration Expert // 6 Months // Nashville, TN

2012-12-03 Thread Aditya
Hi Friends,

This is Aditya Kiran Technical Recruiter for XpertTech in Boston, MA. My client 
is looking to hire a QNXT Configuration Expert for 6+ Months Position.  If you 
available for new opportunities, I would love to speak to you about below 
mentioned job. Thank you for your time in advance and I look forward to your 
response to adi...@xperttech.com or you can reach me on 781-780-2939 X 3041

Location: Nashville, TN
Duration: 6 Months
Rate: OPEN
 
Responsibilities: 
•   Ability to create analyze, interpret and implement business around QNXT 
Core systems
•   Apply previous experience and knowledge to research and resolve 
claim/encounter issues, pended claims and update system(s) as necessary.
•   Participate in the implementation and conversion of new and existing 
health plans.
•   
Maintain thorough and concise documentation for tracking of all provider, 
contract, benefit or reference table configuration change request forms (CCRF) 
for quality audit purposes. Weight complexity for all requests received

Qualification Required:
•   2 - 5 years as Configuration Analyst experience working in Medicare 
industry 
•   Managed Care industry knowledge and specifically Medicare Managed Care 
Technical aptitude, analytical, problem solving and data analysis skills. 
•   Strong project management/organization skills 
•   Excellent verbal & written communication skills 
•   Ability to multi-task and manage concurrent projects 
•   Must have the ability to perform at a high level as an individual and 
as a part of the team. 
•   Proficient with MS Office suite 
•   Knowledge of SQL (database queries, SQL administration) 
•   Knowledge in ICD-9, ICD-10 area
 
Thanks & Regards
Aditya Kiran
Technical Recruiter
  
400 W Cummings Park,
Suite#2850
Woburn, MA-01801
Email: adi...@xperttech.com
Phone: 781-780-2939X3041
Fax: 781-207-0709
 
www.XpertTech.com

Delivering the POWER of Technology
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Puzzling error msg.

2012-12-03 Thread Steven D'Aprano
On Mon, 03 Dec 2012 12:37:42 -0500, wrw wrote:

> So far in my experience with Python, it's error messages have been
> clear, concise, and quite good at fingering my errors.  However, the
> message below has me stumped.  The routine in question has been running
> for weeks with no problems, then yesterday I got the following:
> 
> Traceback (most recent call last):
>   File "./Connection_Monitor.py", line 146, in 
> Google_up, Google_summary, Google_RTT, Google_stddev = 
Google.connection_test()
>   File "/Users/wrw/Dev/Python/Connection_Monitor/Version2.2/WorkingCopy/
network.py",
>   line 101, in connection_test
> #
> IndexError: list index out of range

Are you running Python with the -x option? If so, then I understand that 
the line number (and subsequent line of code) reported in tracebacks may 
sometimes be off by one.

If not, or if the discrepancy is more than one line, I would start 
investigating the following scenario:

* there is a mismatch between the source code .py file and the 
  byte-code .pyc file;

* but the .pyc file's "last modified date" is newer than the .py file;

* the .pyc file is executed (as is usual);

* but when an error occurs and Python looks up the source file, it
  gets something which no longer corresponds to the byte-code being
  executed.



By the way, in connection_test you have the following:

> def connection_test(self):
> found_0 = '0 packets received' in ping_result 
> found_1 = '1 packets received' in ping_result
> if found_0 == True or found_1 == True:
[...]

Of course that's not correct. You should write:

if (found_0 == True or found_1 == True) == True:

No wait, I mean:

if ((found_0 == True or found_1 == True) == True) == True:

No wait! I meant this:

if ((found_0 == True == True == True == True == ... # Help!
   or found_1 == True == True == True == True == ... # Where do I stop?
   ) == True) == True == True == True == True ... :

*wink*

Of course the whole thing is silly. The right way to test booleans for 
their boolean value is just:

if found_0 or found_1:

"flag == True" is the same as "flag".


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


Re: Puzzling error msg.

2012-12-03 Thread Ian Kelly
On Mon, Dec 3, 2012 at 10:37 AM,   wrote:

> if found_0 == True or found_1 == True:
>

Not related to your problem, but this line would be more pythonic as:

if found_0 or found_1:

My puzzle two-fold.  First: how could that code generate an "index our of
> range" error, and second: line 101 (the one fingered by the error message)
> is the line following the return statement, the one that contains the #
> character.  I've seen that sort of line slippage when I forgot a ":", but
> that doesn't seem to be the case here.
>

It may indicate a discrepancy between the source and the code that is
actually running.  Python doesn't keep the source in memory; when a
traceback needs to be generated it opens the relevant files and reads the
designated lines at run-time.  If that source is incorrect, then you get
inaccurate tracebacks.  This could happen in a couple of ways.

1) Your .pyc or .pyo files are out-of-date, and Python doesn't realize it
due to incorrect file modification times.  Try deleting the cached bytecode
files and recompiling and see if your problem goes away (or at least gives
you a better stack trace).

2) It sounds like this is a long-running process, so perhaps the source
code has been changed at some point since the process started.  In that
case, merely restarting the process should be sufficient to fix the stack
trace.

As for the actual error, assuming that the method's source accurately
reflects what was running, the only code I see there that I think could
generate the error is the ".communicate()[0]" bit.  As far as I know,
Popen.communicate should always return a 2-tuple, but perhaps you've
somehow run into a case where it returned an empty tuple instead.  If you
can reproduce the error, you might try logging the result of the
.communicate() call to see what is actually returned when the error occurs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Puzzling error msg.

2012-12-03 Thread wrw
On Dec 3, 2012, at 1:12 PM, Steven D'Aprano 
 wrote:

> On Mon, 03 Dec 2012 12:37:42 -0500, wrw wrote:
> 
>> So far in my experience with Python, it's error messages have been
>> clear, concise, and quite good at fingering my errors.  However, the
>> message below has me stumped.  The routine in question has been running
>> for weeks with no problems, then yesterday I got the following:
>> 
>> Traceback (most recent call last):
>>  File "./Connection_Monitor.py", line 146, in 
>>Google_up, Google_summary, Google_RTT, Google_stddev = 
> Google.connection_test()
>>  File "/Users/wrw/Dev/Python/Connection_Monitor/Version2.2/WorkingCopy/
> network.py",
>>  line 101, in connection_test
>>#
>> IndexError: list index out of range
> 
> Are you running Python with the -x option? If so, then I understand that 
> the line number (and subsequent line of code) reported in tracebacks may 
> sometimes be off by one.
> 

Steven, thanks for looking at this.  No, I'm not using -x and the .py and .pyc 
files are as they should be.  (Notice in the traceback that the files were in 
the "Version2.2/WorkingCopy/" directory.  I'm pretty careful
about version control.)  I've added a bunch of print statements and I'll just 
have to wait until it fails again - hopefully soon.

> 
> 
> By the way, in connection_test you have the following:
> 
>>def connection_test(self):
>>found_0 = '0 packets received' in ping_result 
>>found_1 = '1 packets received' in ping_result
>>if found_0 == True or found_1 == True:
> [...]
> 
> Of course that's not correct. You should write:
> 
> 

[byte]

> Of course the whole thing is silly. The right way to test booleans for 
> their boolean value is just:
> 
> if found_0 or found_1:
> 
> "flag == True" is the same as "flag".
> 
> 

OK - point taken wrt testing booleans.

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

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


Re: Puzzling error msg.

2012-12-03 Thread wrw
On Dec 3, 2012, at 1:27 PM, Ian Kelly  wrote:

> On Mon, Dec 3, 2012 at 10:37 AM,   wrote:
> if found_0 == True or found_1 == True:
> 
> Not related to your problem, but this line would be more pythonic as:
> 
> if found_0 or found_1:
> 

Thanks Ian - yes, Steven pointed out the same thing.  Point well taken.

> My puzzle two-fold.  First: how could that code generate an "index our of 
> range" error, and second: line 101 (the one fingered by the error message) is 
> the line following the return statement, the one that contains the # 
> character.  I've seen that sort of line slippage when I forgot a ":", but 
> that doesn't seem to be the case here.
> 
> It may indicate a discrepancy between the source and the code that is 
> actually running.  Python doesn't keep the source in memory; when a traceback 
> needs to be generated it opens the relevant files and reads the designated 
> lines at run-time.  If that source is incorrect, then you get inaccurate 
> tracebacks.  This could happen in a couple of ways.
> 
> 1) Your .pyc or .pyo files are out-of-date, and Python doesn't realize it due 
> to incorrect file modification times.  Try deleting the cached bytecode files 
> and recompiling and see if your problem goes away (or at least gives you a 
> better stack trace).
> 
> 2) It sounds like this is a long-running process, so perhaps the source code 
> has been changed at some point since the process started.  In that case, 
> merely restarting the process should be sufficient to fix the stack trace.
> 

It is a long-running process, and because of exactly that point I'm pretty 
careful about source code management.  You will notice that the original 
traceback contained the code link: "Version2.2/WorkingCopy/network.py".  In 
other words, I'm pretty careful about segregating my development copies from 
the code I leave running.

> As for the actual error, assuming that the method's source accurately 
> reflects what was running, the only code I see there that I think could 
> generate the error is the ".communicate()[0]" bit.  As far as I know, 
> Popen.communicate should always return a 2-tuple, but perhaps you've somehow 
> run into a case where it returned an empty tuple instead.  If you can 
> reproduce the error, you might try logging the result of the .communicate() 
> call to see what is actually returned when the error occurs.

I was kind of afraid it might be something like that.  I've added some print 
statements and I'll just have to wait for it to fail again (hopefully soon).

Thanks again,
Bill

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


Conversion of List of Tuples

2012-12-03 Thread subhabangalore
Dear Group,

I have a tuple of list as,

tup_list=[(1,2), (3,4)]
Now if I want to covert as a simple list,

list=[1,2,3,4]

how may I do that?

If any one can kindly suggest? Googling didn't help much.

Regards,
Subhabrata. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conversion of List of Tuples

2012-12-03 Thread John Gordon
In <6049bc85-6f8e-429b-a855-ecef47a9d...@googlegroups.com> 
subhabangal...@gmail.com writes:

> Dear Group,

> I have a tuple of list as,

> tup_list=[(1,2), (3,4)]
> Now if I want to covert as a simple list,

> list=[1,2,3,4]

> how may I do that?

new_list = []

for t in tup_list:
for item in t:
new_list.append(item)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Conversion of List of Tuples

2012-12-03 Thread Chris Kaynor
On Mon, Dec 3, 2012 at 11:58 AM,   wrote:
> Dear Group,
>
> I have a tuple of list as,
>
> tup_list=[(1,2), (3,4)]
> Now if I want to covert as a simple list,
>
> list=[1,2,3,4]
>
> how may I do that?
>
> If any one can kindly suggest? Googling didn't help much.

If you know they are always exactly two levels deep, you can use
nested loops (in comprehension form):
[item for tuple_ in list_ for item in tuple_]

That could also be written how John recommended, in three lines.

>
> Regards,
> Subhabrata.
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conversion of List of Tuples

2012-12-03 Thread MRAB

On 2012-12-03 20:04, John Gordon wrote:

In <6049bc85-6f8e-429b-a855-ecef47a9d...@googlegroups.com> 
subhabangal...@gmail.com writes:


Dear Group,



I have a tuple of list as,



tup_list=[(1,2), (3,4)]
Now if I want to covert as a simple list,



list=[1,2,3,4]



how may I do that?


new_list = []

for t in tup_list:
 for item in t:
 new_list.append(item)


Or you could use .extend:

new_list = []

for t in tup_list:
new_list.extend(t)

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


Re: Conversion of List of Tuples

2012-12-03 Thread Chris Angelico
On Tue, Dec 4, 2012 at 7:04 AM, John Gordon  wrote:
> In <6049bc85-6f8e-429b-a855-ecef47a9d...@googlegroups.com> 
> subhabangal...@gmail.com writes:
>
>> Dear Group,
>
>> I have a tuple of list as,
>
>> tup_list=[(1,2), (3,4)]
>> Now if I want to covert as a simple list,
>
>> list=[1,2,3,4]
>
>> how may I do that?
>
> new_list = []
>
> for t in tup_list:
> for item in t:
> new_list.append(item)

Which can be written more succintly as:

new_list = []
for t in tup_list:
new_list.extend(t)

In more general terms, what you're looking to do here is *flatten*
your structure. Not sure if that would have helped in the web search
that you doubtless did before asking this question. :)

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


Re: Puzzling error msg.

2012-12-03 Thread Chris Angelico
On Tue, Dec 4, 2012 at 4:37 AM,   wrote:
> Traceback (most recent call last):
>   File "./Connection_Monitor.py", line 146, in 
> Google_up, Google_summary, Google_RTT, Google_stddev = 
> Google.connection_test()
>   File 
> "/Users/wrw/Dev/Python/Connection_Monitor/Version2.2/WorkingCopy/network.py", 
> line 101, in connection_test
> #
> IndexError: list index out of range
>
>
> The routine is pasted in below:
>
> def connection_test(self):
> self.network_up = True
> self.error = None
> ping_result = subprocess.Popen(['ping', '-qc6', self.target_IP], 
> stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0]
> found_0 = '0 packets received' in ping_result
> found_1 = '1 packets received' in ping_result
> if found_0 == True or found_1 == True:
> self.network_up = False
> self.ping_summary = 'No route to host'
> self.ping_RTT = 'NA'
> self.ping_stddev = 'NA'
> return self.network_up, self.ping_summary, self.ping_RTT, 
> self.ping_stddev
> #

Is that the end of the function? What does it return if neither
found_0 nor found_1? If that's the end, the function will be returning
None (as all functions do on "flowing off the end"), but that would
give a quite different error (namely, 'NoneType' is not iterable, at
the unpacking).

Is it possible that the error actually came from further up (with a
faulty line number) and was actually because communicate() somehow
returned an empty list? That's the only place in the code quoted that
I'm seeing indexing, but communicate() is supposed to return a tuple,
not a list.

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


Re: Conversion of List of Tuples

2012-12-03 Thread subhabangalore
On Tuesday, December 4, 2012 1:28:17 AM UTC+5:30, subhaba...@gmail.com wrote:
> Dear Group,
> 
> 
> 
> I have a tuple of list as,
> 
> 
> 
> tup_list=[(1,2), (3,4)]
> 
> Now if I want to covert as a simple list,
> 
> 
> 
> list=[1,2,3,4]
> 
> 
> 
> how may I do that?
> 
> 
> 
> If any one can kindly suggest? Googling didn't help much.
> 
> 
> 
> Regards,
> 
> Subhabrata.

Thanks. But I am not getting the counter "5posts 0 views"...if moderator can 
please check the issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


A Discussion on Python and Data Visualization

2012-12-03 Thread subhabangalore
Dear Group,

I am trying to work out a data visualization module.

Here,
I am taking raw corpus,and processing it 
linguistically(tokenization,tagging,NED recognition)
and then trying to link the NED's with Latent Semantic Analysis or Relationship 
Mining or Network graph theory or cluster analysis and trying to visualize the 
result.

For NLP based works I am taking NLTK, LSA or Relationship Mining is also 
handled by NLTK,
for Network graph theory I am taking igraph/networkx, for cluster analysis I am 
using Pycluster/Cluster
and if any more extra visualization is required I am using matplotlib.

Now, am I going fine with the choice of software--(I am using Python2.7.3 on 
MS-Windows 7 with IDLE as GUI) or should I change any one?

If you have any suggestion?

Now, I was feeling as this is the age of Information Visualization Python may 
have a library for doing visual analytics which I do not know which would 
extract information and visualize?

If anyone can kindly suggest?

Thanking You in Advance,
Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conversion of List of Tuples

2012-12-03 Thread John Gordon
In  
subhabangal...@gmail.com writes:

> Thanks. But I am not getting the counter "5posts 0 views"...if
> moderator can please check the issue.

I logged in via Google Groups and all the replies were present.  What
is your question?

(This group is not moderated.)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Conversion of List of Tuples

2012-12-03 Thread Steven D'Aprano
On Mon, 03 Dec 2012 13:14:19 -0800, subhabangalore wrote:

> Thanks. But I am not getting the counter "5posts 0 views"...if moderator
> can please check the issue.

What counter are you talking about?

This is an email mailing list, also copied to the Usenet newsgroup 
comp.lang.python, and mirrored on other places including gmane and 
various web sites. Neither email nor Usenet include "counters", so you 
will have to explain what you are talking about.



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


The default locale of sorted()

2012-12-03 Thread Peng Yu
Hi,

I'm not able to find the documentation on what locale is used for
sorted() when the 'cmp' argument is not specified. Could anybody let
me what the default is? If I always want LC_ALL=C, do I need to
explicitly set the locale? Or it is the default?

Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The default locale of sorted()

2012-12-03 Thread Ian Kelly
On Mon, Dec 3, 2012 at 3:17 PM, Peng Yu  wrote:

> Hi,
>
> I'm not able to find the documentation on what locale is used for
> sorted() when the 'cmp' argument is not specified. Could anybody let
> me what the default is? If I always want LC_ALL=C, do I need to
> explicitly set the locale? Or it is the default?
>

The default is that a sorts before b if a < b.  So what you actually want
to know is how strings compare to one another, and the answer from the
Python 3 documentation is:

"Strings are compared lexicographically using the numeric equivalents (the
result of the built-in function
ord())
of their characters."

If you want to sort according to a specific locale, use the locale.strxfrm
key function:

sorted_strings = sorted(original_strings, key=locale.strxfrm)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conversion of List of Tuples

2012-12-03 Thread Walter Hurry
On Mon, 03 Dec 2012 22:11:40 +, Steven D'Aprano wrote:

> On Mon, 03 Dec 2012 13:14:19 -0800, subhabangalore wrote:
> 
>> Thanks. But I am not getting the counter "5posts 0 views"...if
>> moderator can please check the issue.
> 
> What counter are you talking about?
> 
> This is an email mailing list, also copied to the Usenet newsgroup
> comp.lang.python, and mirrored on other places including gmane and
> various web sites. Neither email nor Usenet include "counters", so you
> will have to explain what you are talking about.

Doubtless he is talking about G**gle Groups, since I don't see his posts 
anyway.

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


Working with classes

2012-12-03 Thread laila
Hello, I've been working on this program for a long time but can't seem to get 
it to work.. The first array is the input file, then a class, another class and 
the actual program. Could anyone see what is wrong? I'm sorry if the program 
doesn't make any sense at all  I'm just starting to learn this..

The exercise wants us to do the following:
5,4 4,5 8,7
Add behind 6,3 3,2 9,6 4,3
Add in front 7,6
Add behind 9,8
Add in front 5,5 7,8 6,5 6,4
These are coordinates in the form(x,y) and the x coordinates need to be raised 
by 1.

pirateinvoer:
5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4




'''
Created on 2 dec. 2012

@author: Laila
'''
class CoordinateRow():
def __init__(self) :
self.coordinate_row = []

def row_even(self,EVEN, rows):
self.row_even=[rows[row] for row in EVEN]
return self.row_even

def row_odd(self,ONEVEN,rows):
self.row_odd=[rows[row] for row in ONEVEN]
return self.row_odd

def rows_front(self,index, row_front):
self.new_row_front=self.row_even.insert(index,row_front)
return self.new_row_front

def rows_back(self,index, row_back):
self.new_row_back=self.row_odd.append(index,row_back)
return self.new_row_back



class Coordinaat: 
def __init__(self,x,y):
self.x = x
self.y = y



def correct_coordinates(self, OPHOGING_X, OPHOGING_Y):
self.x=self.x + OPHOGING_X
self.y=self.y + OPHOGING_Y
return self.y
return self.x


from coordinaat import Coordinaat
from coordinate_row import CoordinateRow

file_input=file('pirateinvoer','r')
all_coordinates=file_input.read()
EVEN=range(0,4,2)
ONEVEN=range(1,5,2)
OPHOGING_X=1
OPHOGING_Y=0

def make_coordinate_row(all_coordinate_rows):
for coordinate_rows in all_coordinate_rows:
coordinate_rows=coordinate_rows.split()

make_x_y(coordinate_rows)

def make_x_y(coordinate_rows):
for coordinate_row in coordinate_rows:
x_y=coordinate_row.split(',')
return Coordinaat (x_y[0],x_y[1])

def make_route(coordinate_rows):
result=[]
new_row=row.coordinate_rows.row_even(EVEN, coordinate_rows)
result+=new_row

new_row=row.coordinate_rows.row_oneven(ONEVEN, coordinate_rows)
result+=new_row

print result

all_coordinate_rows = all_coordinates.strip().split('=')
make_coordinate_row(all_coordinate_rows)
for coordinates in all_coordinate_rows:
row = CoordinateRow()
print row







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


noob: print and file.read()

2012-12-03 Thread Andrew Z
Hello,
 why the following code doesn't print the content of the file:
#!/usr/bin/python

from_file ="file.txt"
in_file = open(from_file)
str = in_file.read()
print "Here should be the output from the file - ", in_file.read()
print "Here should be the output from the STR- ", str in_file.close()


The first "print" has nothing whereas the second properly displays the
content of the file.

Thank you
AZ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: noob: print and file.read()

2012-12-03 Thread MRAB

On 2012-12-03 23:06, Andrew Z wrote:

Hello,
  why the following code doesn't print the content of the file:
#!/usr/bin/python

from_file ="file.txt"
in_file = open(from_file)
str = in_file.read()


You've read the entire file, leaving the file pointer positioned at the
end of the file.


print "Here should be the output from the file - ", in_file.read()


You're trying to read the file again, but the file pointer is still
positioned at the end of the file, and there's no more left to read.

If you want to read it again, you'll need to reset the file pointer
back to the start of the file using in_file.seek(0).


print "Here should be the output from the STR- ", str

> in_file.close()



The first "print" has nothing whereas the second properly displays the
content of the file.



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


Re: Working with classes

2012-12-03 Thread Rhodri James

On Mon, 03 Dec 2012 22:47:53 -,  wrote:

Hello, I've been working on this program for a long time but can't seem  
to get it to work.


I'm sorry, you are going to have to be a lot clearer.  It isn't even a
little bit obvious what you are talking about, which rather makes me
suspect this is a homework question :-)


The first array is the input file,


What array?  Do you mean the string of numbers haphazardly separated
by spaces, commas and equals signs?


then a class, another class and the actual program.


Are those in separate files?  Your "import" statements suggest they
are, but you don't give us any other hints.


Could anyone see what is wrong?


It's a bit hard to do that when you don't tell us what "right" means
in this case, and why you think your program might be wrong.

I'm sorry if the program doesn't make any sense at all  I'm just  
starting to learn this.


The program makes perfectly good sense, it is your description that
I don't understand.  Please tell us what it is supposed to do, and
what makes you think it doesn't do it.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Can't get simplegui to display cards in Codesculptor (Blackjack project)

2012-12-03 Thread yambury
Help - I don't want to give up on this.  I have all the logic working, but 
can't  draw the cards on the canvas.

Here is my link - Please try it out and offer suggestions

http://www.codeskulptor.org/#user7-Ok26As4ZzMIuXVH-12.py

Thanks,

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


Re: Puzzling error msg.

2012-12-03 Thread Dave Angel
On 12/03/2012 03:33 PM, Chris Angelico wrote:
> 
> Is it possible that the error actually came from further up (with a
> faulty line number) and was actually because communicate() somehow
> returned an empty list? That's the only place in the code quoted that
> I'm seeing indexing, but communicate() is supposed to return a tuple,
> not a list. ChrisA 
Tuples can also be empty.  Try j = () for example, and look at its type
and length.

No idea if this is the problem, but just wanted to nitpick.


-- 

DaveA

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


Re: noob: print and file.read()

2012-12-03 Thread Andrew Z
Mrab,
 you nailed it. thank you very much!
AZ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Working with classes

2012-12-03 Thread Chris Angelico
On Tue, Dec 4, 2012 at 9:47 AM,   wrote:
> Hello, I've been working on this program for a long time but can't seem to 
> get it to work.. The first array is the input file, then a class, another 
> class and the actual program. Could anyone see what is wrong? I'm sorry if 
> the program doesn't make any sense at all  I'm just starting to learn this..
>
> The exercise wants us to do the following:

Hi! Thanks for being up-front about it being homework :)

In what way does your code not work? Is it giving an exception? Paste
the exception and traceback to us - it'll be a lot easier to see
what's going on.

> file_input=file('pirateinvoer','r')
> all_coordinates=file_input.read()

No idea if it's your issue or not, but this is an unusual way to read
files. Normally you'll want to use the open() function, and probably
use 'with' to ensure it's closed promptly.

Note that Python is not Java. You don't have to put one class in one
file. Instead of importing classes from other files, just have them
all in your main file - it makes a lot more sense, usually. In Python,
a file usually is a module, on par with the modules in the standard
library. It can contain lots of (related) classes and functions.

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


Re: Puzzling error msg.

2012-12-03 Thread Chris Angelico
On Tue, Dec 4, 2012 at 1:28 PM, Dave Angel  wrote:
> On 12/03/2012 03:33 PM, Chris Angelico wrote:
>> 
>> Is it possible that the error actually came from further up (with a
>> faulty line number) and was actually because communicate() somehow
>> returned an empty list? That's the only place in the code quoted that
>> I'm seeing indexing, but communicate() is supposed to return a tuple,
>> not a list. ChrisA
> Tuples can also be empty.  Try j = () for example, and look at its type
> and length.
>
> No idea if this is the problem, but just wanted to nitpick.

They can, yes, but the error said *list* index out of range. That
shouldn't happen off an empty tuple.

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


Re: Puzzling error msg.

2012-12-03 Thread Dave Angel
On 12/03/2012 10:28 PM, Chris Angelico wrote:
> On Tue, Dec 4, 2012 at 1:28 PM, Dave Angel  wrote:
>> On 12/03/2012 03:33 PM, Chris Angelico wrote:
>>> 
>>> Is it possible that the error actually came from further up (with a
>>> faulty line number) and was actually because communicate() somehow
>>> returned an empty list? That's the only place in the code quoted that
>>> I'm seeing indexing, but communicate() is supposed to return a tuple,
>>> not a list. ChrisA
>> Tuples can also be empty.  Try j = () for example, and look at its type
>> and length.
>>
>> No idea if this is the problem, but just wanted to nitpick.
> They can, yes, but the error said *list* index out of range. That
> shouldn't happen off an empty tuple.
>

Quite right.  I missed that part of the context. Sorry.

-- 

DaveA

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


how to split the file into two sections....

2012-12-03 Thread indu_shreenath
Hi:
I have a text as 
version comp X - aa
version comp Y - bbb
version comp Z -cc

12.12 Check for option 1

12:13 Pass Test 1
12:14 verified bla bla bla
12.15 completed

12.16 Fail Test 2
12:17 verified bla bla bla
12.18 completed

12.19 Fail Test 3
12:20 verified bla bla bla
12.21 completed

12.22 Check for option B

12:23 Pass Test4
12:24 verified bla bla bla
12.25 completed

12.26 Fail Test 5
12:27 verified bla bla bla
12.28 completed

12.29 Fail Test 6
12:30 verified bla bla bla
12.31 completed

 In this I want to split the file to two sections to post the summary as 

Check for option 1
Pass 2 
Fail 1
Check for option 2
Pass 2 
Fail 1
-- 
http://mail.python.org/mailman/listinfo/python-list