Re: one-element tuples

2016-04-11 Thread Jussi Piitulainen
Fillmore writes:

> so, I do not quite control the format of the file I am trying to
> parse.
>
> it has the format:
>
> "str1","str2",,"strN" => more stuff
>   :
>
> in some cases there is just one "str" which is what created me
> problem.  The first "str1" has special meaning and, at times, it can
> be alone.
>
> The way I handle this is:
>
> parts = line.strip().split(" => ")
> tokens = eval(parts[0])
>
> if type(tokens) == str:   #Handle case that there's only one token

[- -]

> else:

[- -]

> which admittedly is not very elegant. If you have suggestions on how
> to avoid the use of eval() and still achieve the same, I would be
> delighted to hear them

It depends on what a "strK" can be. You already trust that it cannot be
"A => B", but can it be "A, B"? Can it be '"Literally" this'? Or "\"".
That is, can the strings contain commas or quote characters?

If not, some variant of this may be preferable:

[ item.strip('"') for item in parts[0].split(',') ]

Or something like this:

re.findall('[^",]+', parts[0])

Both are brittle if the format allows the crucial characters to occur
(or not occur) in different ways. The regex way may be flexible enough
to deal with the details, but it would be more complicated than the
above example.

One thing would be easy to do either way: _check_ the line for no
surprises, and _then_ proceed to split, or raise an alert, or deal with
each detected special case specially.

If the format allows commas or doublequotes inside the strings, the
quotation rules may be such that you might be able to abuse the CSV
reader to interpret them. It depends much on the details, and is not
different from the way you are currently relying on the first part of
the line following Python's expression syntax.

next(csv.reader(io.StringIO('"fo,o",\'"bar"\'')))
# => ['fo,o', '\'"bar"\'']
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Most probably a stupid question, but I still want to ask

2016-04-11 Thread Rustom Mody
On Monday, April 11, 2016 at 11:12:39 AM UTC+5:30, Stephen Hansen wrote:
> On Sun, Apr 10, 2016, at 10:18 PM, Rustom Mody wrote:
> > On Monday, April 11, 2016 at 10:17:13 AM UTC+5:30, Stephen Hansen wrote:
> > > On Sun, Apr 10, 2016, at 09:03 PM, Fillmore wrote:
> > > > and the (almost always to be avoided) use of eval()
> > > 
> > > FWIW, there's ast.literal_eval which is safe and there's no reason to
> > > avoid it.
> > 
> > Its error reporting is clunky:
> > 
> > >>> from ast import literal_eval as le
> > >>> le("(1)")
> > 1
> > >>> le("(1,)")
> > (1,)
> > >>> le("1")
> > 1
> > >>> le("{1:x}")
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File "/usr/lib/python2.7/ast.py", line 80, in literal_eval
> > return _convert(node_or_string)
> >   File "/usr/lib/python2.7/ast.py", line 63, in _convert
> > in zip(node.keys, node.values))
> >   File "/usr/lib/python2.7/ast.py", line 62, in 
> > return dict((_convert(k), _convert(v)) for k, v
> >   File "/usr/lib/python2.7/ast.py", line 79, in _convert
> > raise ValueError('malformed string')
> > ValueError: malformed string
> 
> So? Worst case scenario, someone puts invalid data into the file and it
> throws an exception. Could it be more specific? Maybe, but I don't see
> why it needs to be. If your input isn't reliably formatted, catch
> ValueError and log it and fix (either what wrote it or change how you
> read it).

Sorry... Didnt mean "dont use!"
Just "Heres a flipside to consider"
Also that the OP's question is not a classic "Avoid eval like the plague"
but "Many nooks and crannies in the syntax" issue
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-11 Thread Tim Chase
On 2016-04-11 01:33, MRAB wrote:
> A one-element tuple can be written as:
> 
>  >>> ('hello',)  
> ('hello',)
> 
> As has been said already, it's the comma that makes the tuple. The 
> parentheses are often needed to avoid ambiguity.

Except when the comma *doesn't* make the tuple:

   >>> t = ()
   >>> type(t)
   

;-)

-tkc


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


Re: Most probably a stupid question, but I still want to ask

2016-04-11 Thread Steven D'Aprano
On Monday 11 April 2016 14:03, Fillmore wrote:

> I'll make sure I approach the temple of pythonistas bare-footed and with
> greater humility next time

Don't forget to rip your clothes into rags and heap ashes on your head too.


-- 
Steve

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


Re: Parens do create a tuple

2016-04-11 Thread Steven D'Aprano
On Monday 11 April 2016 15:27, Random832 wrote:

> On Mon, Apr 11, 2016, at 00:08, Steven D'Aprano wrote:
>> Should we say that the / and - operators therefore create tuples? I don't
>> think so.
> 
> But I am talking about the tuple that is passed to FunctionType.__call__
> at runtime, not a tuple created within some parser stage.


What tuple that is passed to FunctionType.__call__?

Where is the tuple in these examples?


py> from types import FunctionType
py> FunctionType.__call__(lambda x: x+1, 23)
24
py> FunctionType.__call__(lambda x, y: str(x)+str(y), 23, 42)
'2342'

I don't see any evidence of a tuple being involved anywhere visible from 
Python code. How do you know that there's a tuple involved? (That's not a 
rhetorical question, I am genuinely curious.)

In you want to tell me that, deep inside the CPython implementation, 
function calls involve an invisible and inaccessible tuple of arguments, 
then I'll say "That's interesting, but not really relevant." There could be, 
and probably are, all sorts of places in Python's implementation where 
tuples are used internally. But that's not a language feature, its an 
implementation detail.



-- 
Steve

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


Re: Python,ping,csv

2016-04-11 Thread Smith

Il 10/04/2016 05:29, Jason Friedman ha scritto:

for ping in range(1,254):
 address = "10.24.59." + str(ping)
 res = subprocess.call(['ping', '-c', '3', address])
 if res == 0:
 print ("ping to", address, "OK")
 elif res == 2:
 print ("no response from", address)
 else:
 print ("ping to", address, "failed!")


Note that with Python 3.3+ you can simplify slightly:

from ipaddress import IPv4Network
for address in IPv4Network('10.24.59.0/24').hosts():
 res = subprocess.call(['ping', '-c', '3', address])
 ...


Thanks a lot ;-)
--
https://mail.python.org/mailman/listinfo/python-list


Re: numpy arrays

2016-04-11 Thread Heli
Thanks Oscar, 

In my case this did the trick. 
sortedVal=np.array(val[ind]).reshape((xcoord.size,ycoord.size,zcoord.size))

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


Re: Python,ping,csv

2016-04-11 Thread Smith

Il 10/04/2016 05:29, Jason Friedman ha scritto:

for ping in range(1,254):
 address = "10.24.59." + str(ping)
 res = subprocess.call(['ping', '-c', '3', address])
 if res == 0:
 print ("ping to", address, "OK")
 elif res == 2:
 print ("no response from", address)
 else:
 print ("ping to", address, "failed!")


Note that with Python 3.3+ you can simplify slightly:

from ipaddress import IPv4Network
for address in IPv4Network('10.24.59.0/24').hosts():
 res = subprocess.call(['ping', '-c', '3', address])
 ...




I added a line.
I would need to put the output into a csv file which contained the 
results of the hosts up and down.

Can you help me?


import subprocess
from ipaddress import IPv4Network
for address in IPv4Network('10.24.59.0/24').hosts():
a = str(address)
res = subprocess.call(['ping', '-c', '3', address])



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


Re: numpy arrays

2016-04-11 Thread Heli
As you said, this did the trick. 
sortedVal=np.array(val[ind]).reshape((xcoord.size,ycoord.size,zcoord.size)) 

Only val[ind] instead of val[ind,:] as val is 1D. 

Thanks Oscar, 


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


Re: one-element tuples

2016-04-11 Thread BartC

On 11/04/2016 01:48, Fillmore wrote:

On 04/10/2016 08:31 PM, Ben Finney wrote:

Can you describe explicitly what that “discontinuation point” is? I'm
not seeing it.


Here you go:

 >>> a = '"string1"'
 >>> b = '"string1","string2"'
 >>> c = '"string1","string2","string3"'
 >>> ea = eval(a)
 >>> eb = eval(b)
 >>> ec = eval(c)
 >>> type(ea)
   <--- HERE 
 >>> type(eb)

 >>> type(ec)


I can tell you that it exists because it bit me in the butt today...

and mind you, I am not saying that this is wrong. I'm just saying that
it surprised me.


I think this shows more clearly what you mean:

a = 10 # int
b = 10,# tuple
c = 10,20  # tuple
d = 10,20,30   # tuple

The difference between a and b is that trailing comma. A bit of a 
kludge, but it's enough to distinguish between a single value (x), and a 
one-element tuple (x,).


In this case, you might call it a discontinuity in the syntax as, when 
you go from d to c, you remove ",30", including the comma, but when 
going from c to b, you remove only "20".


But this can be fixed if tuples are written like this:

a = 10 # int
b = 10,# tuple
c = 10,20, # tuple
d = 10,20,30,  # tuple

Now, you remove "30," then "20,". No exception.

Of course this doesn't help you parsing typical input which uses commas 
as separators, not terminators!



--
Bartc





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


[no subject]

2016-04-11 Thread DEEPAK KUMAR PAWAR
I am trying to install numpy along with the python35
But it getting error everytime.



Sent from Mail for Windows 10

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


installation problem

2016-04-11 Thread palak pandey
i m not able to install python software in my windows 10 os...
i have provided u with the image of error that is occurring during
installation
[image: Inline image 1]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: one-element tuples

2016-04-11 Thread Marko Rauhamaa
BartC :

> Of course this doesn't help you parsing typical input which uses
> commas as separators, not terminators!

That's a red herring. You mustn't parse with eval(). You shouldn't event
think of parsing non-Python data with eval(). Why should Python's syntax
resemble a CSV file?

Try compiling the data file with a C compiler or bash.

The real answer is to do:

"a,b,c".split(",")
==> ['a', 'b', 'c']

Now, tuples would be trivial:

tuple("a,b,c".split(","))
==> ('a', 'b', 'c')

but a tuple is probably not what you'd want here since the number of
data elements in the OP's question is not constant.


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


Re: installation problem

2016-04-11 Thread Igor Korot
Hi, Palak,

On Sun, Apr 10, 2016 at 2:30 AM, palak pandey  wrote:
> i m not able to install python software in my windows 10 os...
> i have provided u with the image of error that is occurring during
> installation
> [image: Inline image 1]

Attachments are not allowed on this list.

Please copy and paste the error you receive in the email.

Thank you.

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


Re:

2016-04-11 Thread Igor Korot
Hi,

On Sat, Apr 9, 2016 at 11:37 AM, DEEPAK KUMAR PAWAR
 wrote:
> I am trying to install numpy along with the python35
> But it getting error everytime.

What error you receive?

Please copy and paste the error as this list does not allow screenshots...

Thank you.

>
>
>
> Sent from Mail for Windows 10
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parens do create a tuple

2016-04-11 Thread Random832
On Mon, Apr 11, 2016, at 04:01, Steven D'Aprano wrote:
> What tuple that is passed to FunctionType.__call__?
> 
> Where is the tuple in these examples?
> 
> 
> py> from types import FunctionType
> py> FunctionType.__call__(lambda x: x+1, 23)
> 24
> py> FunctionType.__call__(lambda x, y: str(x)+str(y), 23, 42)
> '2342'
> 
> I don't see any evidence of a tuple being involved anywhere visible from 
> Python code.

The fact that it can be called with two positional arguments in your
first example, and three in your second, is itself weak evidence for
this (more evidence is needed to show that these aren't
keyword/positional arguments with defaults) - a pure python function
that behaved as FunctionType.__call__ would have to be defined with
*args and **kwargs. And, indeed...

>>> inspect.signature(FunctionType.__call__)


I am assuming that *args' use of a tuple is defined as part of the
language. If I'm mistaken and it can be any sequence, I suppose I stand
corrected.

> How do you know that there's a tuple involved? (That's not a 
> rhetorical question, I am genuinely curious.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: one-element tuples

2016-04-11 Thread Grant Edwards
On 2016-04-11, Ben Finney  wrote:
> Fillmore  writes:
>>
>> I can tell you that it exists because it bit me in the butt today...
>>
>> and mind you, I am not saying that this is wrong. I'm just saying that
>> it surprised me.
>
> What behaviour did you expect instead? That's still unclear.

I must admit this is one of the best trolls I've seen in a while...

-- 
Grant Edwards   grant.b.edwardsYow! GOOD-NIGHT, everybody
  at   ... Now I have to go
  gmail.comadminister FIRST-AID to my
   pet LEISURE SUIT!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: one-element tuples

2016-04-11 Thread Fillmore

On 04/11/2016 10:10 AM, Grant Edwards wrote:


What behaviour did you expect instead? That's still unclear.


I must admit this is one of the best trolls I've seen in a while...



shall I take it as a compliment?
--
https://mail.python.org/mailman/listinfo/python-list


Re: one-element tuples

2016-04-11 Thread Grant Edwards
On 2016-04-11, Marko Rauhamaa  wrote:
> BartC :
>
>> Of course this doesn't help you parsing typical input which uses
>> commas as separators, not terminators!
>
> That's a red herring. You mustn't parse with eval(). You shouldn't event
> think of parsing non-Python data with eval().

And you problably shouldn't think of parsing Python data with eval()
either -- but for different reasons: It's very difficult to use eval()
safely.

-- 
Grant Edwards   grant.b.edwardsYow! I want you to MEMORIZE
  at   the collected poems of
  gmail.comEDNA ST VINCENT MILLAY
   ... BACKWARDS!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Is threading better on Usenet or gmane?

2016-04-11 Thread Grant Edwards
I've been reading c.l.p on Usenet for many, many years.  There has
always been a certain abount of thread breakage (presumably due to
broken e-mail clients and/or the list<->usenet gateway), but it seems
to have gotten worse lately.

Has anybody noticed whether the threading is less broken if one reads
the list on gmane?  Everytime I decide to try to do a direct
comparison, I can't find enough thread breaks to tell if there's a
significant difference.

-- 
Grant Edwards   grant.b.edwardsYow! Somewhere in Tenafly,
  at   New Jersey, a chiropractor
  gmail.comis viewing "Leave it to
   Beaver"!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: one-element tuples

2016-04-11 Thread Grant Edwards
On 2016-04-11, Fillmore  wrote:
> On 04/11/2016 10:10 AM, Grant Edwards wrote:
>
>>> What behaviour did you expect instead? That's still unclear.
>>
>> I must admit this is one of the best trolls I've seen in a while...
>
> shall I take it as a compliment?

That depends on your intent, so only you really know the answer.

-- 
Grant Edwards   grant.b.edwardsYow! I hope something GOOD
  at   came in the mail today so
  gmail.comI have a REASON to live!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is threading better on Usenet or gmane?

2016-04-11 Thread Random832
On Mon, Apr 11, 2016, at 10:24, Grant Edwards wrote:
> I've been reading c.l.p on Usenet for many, many years.  There has
> always been a certain abount of thread breakage (presumably due to
> broken e-mail clients and/or the list<->usenet gateway), but it seems
> to have gotten worse lately.
> 
> Has anybody noticed whether the threading is less broken if one reads
> the list on gmane?  Everytime I decide to try to do a direct
> comparison, I can't find enough thread breaks to tell if there's a
> significant difference.

I've already outlined under what circumstances threading is likely to be
broken (before the recent changes):

| For users reading by the mailing list, Usenet users' replies to
| Mailing List users will be broken (but their replies to each other
| will be fine). For users reading by Usenet, Mailing List users'
| replies to each other will be broken (though all replies made via
| Usenet or to Usenet users will be fine).

gmane is essentially the same as reading it by email as far as this
issue is concerned.

What the new change (see Mark Sapiro's recent posts on this topic)
should fix is the first half of that. It doesn't necessarily do anything
about the second half:

Email User A posts message [email protected], this becomes [email protected] (the
new change makes this look like a reply to the nonexistent [email protected])
Email User D replies with [email protected], this becomes [email protected] (but
still says it's a reply to [email protected])
Usenet User G replies (to A/B) with [email protected], this is a reply to
[email protected], but (with the new change) acknowledges [email protected] as the
"grandparent article", so mailing list users should still see it under
B's thread.

So, even though D's message is a reply to A's message, it won't show up
that way on usenet. G's message should show up fine on both.


Everything would be perfect if everyone posted to Usenet and read by
email/gmane.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is threading better on Usenet or gmane?

2016-04-11 Thread Grant Edwards
On 2016-04-11, Random832  wrote:

> I've already outlined under what circumstances threading is likely
> to be broken (before the recent changes):
>
>| For users reading by the mailing list, Usenet users' replies to
>| Mailing List users will be broken (but their replies to each other
>| will be fine). For users reading by Usenet, Mailing List users'
>| replies to each other will be broken (though all replies made via
>| Usenet or to Usenet users will be fine).
>
> gmane is essentially the same as reading it by email as far as this
> issue is concerned.
>
> What the new change (see Mark Sapiro's recent posts on this topic)
> should fix is the first half of that. It doesn't necessarily do anything
> about the second half:

OK. So recent fix should fix all gateway-related thread breakage for
mailing-list readers (which includes gmane).  I had read most of the
thread on that change, but was still confused about exactly what was
getting fixed.

Thanks for clarifying it.

-- 
Grant Edwards   grant.b.edwardsYow! I'll eat ANYTHING
  at   that's BRIGHT BLUE!!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is threading better on Usenet or gmane?

2016-04-11 Thread Grant Edwards
On 2016-04-11, Grant Edwards  wrote:

I just finished checking a very recent thread containing 67 articles
by pointing slrn at news.panix.com for the Usenet version and at
news.gmane.com for the mailing-list version.

Both servers appeared to show the same set of 67 articles (that alone
is pretty good) though the tree structures were rather different.

Then I checked each article to see if its parent article was availble.

On the Usenet side, 35 of 67 articles had unavailable parent articles,
which is pretty bad compared to non-gatewayed groups.

On the mailing-list side 15 of 67 had unavailable parent articles,
which is a bit shabby by general usenet standards, but probably pretty
decent for gatewayed groups.

How representative that thread was is left as an exercise for the
reader.

-- 
Grant Edwards   grant.b.edwardsYow! If Robert Di Niro
  at   assassinates Walter Slezak,
  gmail.comwill Jodie Foster marry
   Bonzo??
-- 
https://mail.python.org/mailman/listinfo/python-list


python pandas convert strings to datetime problems

2016-04-11 Thread Daiyue Weng
Hi, I need to compare the years in a Series. The values in the Series is
like '1996', '2015', '2006-01-02' or '20130101' etc. The code I created is,

col_value_series = pd.to_datetime(col_value_series, infer_datetime_format=True)
min_year = col_value_series.min().year
max_year = col_value_series.max().year

current_year = datetime.date.today().year

res1 = min_year > 1970
res2 = max_year < current_year
return min_year > 1970 and max_year < current_year

the code is working fine on the values like '20030101' and '2006-01-02',
which are converted to datetime, i.e. '2003-01-01'. But it converted values
'1996' or '2015' to '1970-01-01 00:00:00.01996' and '1970-01-01
00:00:00.02015', which are completely wrong (meaning the years are all
1970 now). So how to resolve the issue.

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


Re: Is threading better on Usenet or gmane?

2016-04-11 Thread Grant Edwards
On 2016-04-11, Grant Edwards  wrote:
> On 2016-04-11, Grant Edwards  wrote:
>
> I just finished checking a very recent thread containing 67 articles
> by pointing slrn at news.panix.com for the Usenet version and at
> news.gmane.com for the mailing-list version.
[...]
> On the Usenet side, 35 of 67 articles had unavailable parent
> articles,
[...]
> On the mailing-list side 15 of 67 had unavailable parent articles,

FWIW, an automated test on the 1000 most recent articles showed this:

 Usenet   Gmane
No References  69  104
   Unavailable Parent 357   34

Due to moderation/filtering, the set of articles from the two servers
probably isn't identical.

For posts that aren't follow-ups, no references is normal, but I'm
surprised by the size of the difference in number of articles with no
references header.

An unavailable parent means that there _was_ a refrences header, but
the most recent reference didn't map to an available article on the
server in question.

In general, the situation appears to be significantly better on Gmane
-- even if we assume that the excess number of "no reference"
ariticles on Gmane indicates those articles are broken and should have
references.

-- 
Grant Edwards   grant.b.edwardsYow! Let me do my TRIBUTE
  at   to FISHNET STOCKINGS ...
  gmail.com

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


Re: python pandas convert strings to datetime problems

2016-04-11 Thread Peter Otten
Daiyue Weng wrote:

> Hi, I need to compare the years in a Series. The values in the Series is
> like '1996', '2015', '2006-01-02' or '20130101' etc. The code I created
> is,
> 
> col_value_series = pd.to_datetime(col_value_series,
> infer_datetime_format=True) min_year = col_value_series.min().year
> max_year = col_value_series.max().year
> 
> current_year = datetime.date.today().year
> 
> res1 = min_year > 1970
> res2 = max_year < current_year
> return min_year > 1970 and max_year < current_year
> 
> the code is working fine on the values like '20030101' and '2006-01-02',
> which are converted to datetime, i.e. '2003-01-01'. But it converted
> values '1996' or '2015' to '1970-01-01 00:00:00.01996' and '1970-01-01
> 00:00:00.02015', which are completely wrong (meaning the years are all
> 1970 now). So how to resolve the issue.

This seems to happen when the year-only dates are integers. Compare:

>>> import pandas as pd
>>> pd.to_datetime(pd.Series(["2010-10-20", 2000]))
0  2010-10-20 00:00:00
1   1970-01-01 00:00:00.02
dtype: datetime64[ns]
>>> pd.to_datetime(pd.Series(["2010-10-20", "2000"]))
0   2010-10-20
1   2000-01-01
dtype: datetime64[ns]

How is your series created? Perhaps you can ensure that you start out with 
strings only.

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


OT: Anyone here use the ConEmu console app?

2016-04-11 Thread DFS
I turned on the Quake-style option (and auto-hide when it loses focus) 
and it disappeared and I can't figure out how to get it back onscreen. I 
think there's a keystroke combo (like Win+key) but I don't know what it is.


It shows in the Task Manager Processses, but not in the Alt+Tab list.

Uninstalled and reinstalled and now it launches Quake-style and hidden. 
 Looked everywhere (\Users\AppData\Local, Registry) for leftover 
settings file but couldn't find it.


Here's the screen where you make the Quake-style setting.
https://conemu.github.io/en/SettingsAppearance.html



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


Re: OT: Anyone here use the ConEmu console app?

2016-04-11 Thread 20/20 Lab

win+alt+space does not work?  ctrl+alt+win+space?

http://conemu.github.io/en/KeyboardShortcuts.html

Says those are not configurable, so they should work.

On 04/11/2016 02:49 PM, DFS wrote:
I turned on the Quake-style option (and auto-hide when it loses focus) 
and it disappeared and I can't figure out how to get it back onscreen. 
I think there's a keystroke combo (like Win+key) but I don't know what 
it is.


It shows in the Task Manager Processses, but not in the Alt+Tab list.

Uninstalled and reinstalled and now it launches Quake-style and 
hidden.  Looked everywhere (\Users\AppData\Local, Registry) for 
leftover settings file but couldn't find it.


Here's the screen where you make the Quake-style setting.
https://conemu.github.io/en/SettingsAppearance.html



Thanks


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


Re: REMOVE ME

2016-04-11 Thread John Pote

On 10/04/2016 04:52, Chris Angelico wrote:

On Sun, Apr 10, 2016 at 1:46 PM, fan nie  wrote:

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

Sure. I presume you mean something like this:

class Thing:
 things = []
 def __init__(self):
 self.things.append(self)
 def __del__(self):
 # Remove me when I'm dead
 self.things.remove(self)

This ingenious technique guarantees that you never have dead objects
in your list, by having each object remove itself when it dies.

ChrisA
I'm not quite sure how tongue in cheek ChrisA's reply and the Thing 
class was but it did make me think and wonder if my understanding of 
Python lore was quite right. To my mind it looks like a Zombie or even 
Revenant class.


If all external references to an instance of Thing are deleted there is 
still the reference from the class list 'things []'. In which case will 
not this prevent the instance from being garbage collected and __del__() 
never called on the dead instance and its memory never released. But a 
memory dump could reveal the ghost of the instance. On the other hand a 
code wizard with the right lore could resurect the instance by getting 
the reference to it and bring it back to life -

revenant = Thing.things[x]

But then I notice 'things' is used as an instance attribute rather than 
a class attribute. All seems to be shrouded in a web of mystery


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


Re: REMOVE ME

2016-04-11 Thread Steven D'Aprano
On Tue, 12 Apr 2016 08:44 am, John Pote wrote:

> On 10/04/2016 04:52, Chris Angelico wrote:
>> On Sun, Apr 10, 2016 at 1:46 PM, fan nie  wrote:
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>> Sure. I presume you mean something like this:
>>
>> class Thing:
>>  things = []
>>  def __init__(self):
>>  self.things.append(self)
>>  def __del__(self):
>>  # Remove me when I'm dead
>>  self.things.remove(self)
>>
>> This ingenious technique guarantees that you never have dead objects
>> in your list, by having each object remove itself when it dies.
>>
>> ChrisA
> I'm not quite sure how tongue in cheek ChrisA's reply and the Thing
> class was 

I'm sure it was extremely tongue in cheek.


> but it did make me think and wonder if my understanding of 
> Python lore was quite right. To my mind it looks like a Zombie or even
> Revenant class.
> 
> If all external references to an instance of Thing are deleted there is
> still the reference from the class list 'things []'. In which case will
> not this prevent the instance from being garbage collected and __del__()
> never called on the dead instance and its memory never released. 

Correct.


> But a 
> memory dump could reveal the ghost of the instance. On the other hand a
> code wizard with the right lore could resurect the instance by getting
> the reference to it and bring it back to life -
>  revenant = Thing.things[x]
> 
> But then I notice 'things' is used as an instance attribute rather than
> a class attribute. All seems to be shrouded in a web of mystery

Your first analysis was correct. "self.things" is actually a class
attribute, despite being accessed from "self". The reason being, attribute
lookups look for:

- instance attributes;
- class attributes;
- superclass attributes;

in that order. (This is actually an extremely simplified view, but close
enough for what we're discussing.) Hence "self.things" will return the same
list each time, the one defined as a class attribute, regardless of
which "self" does the lookup.

If a method were to assign to the attribute, for example "self.things = []",
that would create an instance attribute, but that doesn't happen.



-- 
Steven

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


"unable to find vcvarsall.bat"

2016-04-11 Thread Terry Reedy

Blog post by Steve Dower of Microsoft and CPython core developer.
'''How to deal with the pain of “unable to find vcvarsall.bat”'''
https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/

Explains the message and the two solutions: get the needed C compiler; 
get a precompiled binary.


--
Terry Jan Reedy


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


!! Immediate Position:Technical Consultant at (The Woodlands, TX) !!

2016-04-11 Thread sourav524 . itscient
Hi All , 
Please go through the below job description and let me know your interest.

Position:  Technical Consultant
Location: The Woodlands, TX
Duration: 6+ Months 
 
Requisition Details:
 
Job Description:-
 
QUALIFICATIONS  
 
• Over 5 years of IT applications experience is required, preferably on 
Environmental, Health and Safety applications.
• Job Knowledge: Exhibits skills and experience in all phases of application 
systems development and implementation, including analysis/design, 
blueprinting, configuration, documentation, testing, training, and support.  In 
addition the candidate should also have a working knowledge of systems 
architecture, systems integration, data analysis, data modeling, and data base 
design.
• Technical/Functional support experience is highly desirable in the following 
areas:
o Technical: (mandatory)
 Server operations – Server 2003, 2008, 2008R2, 2012, 2012R2
 IIS and Tomcat
 Oracle and SQL Databases (No direct access to DB’s on server, DB’s accessed 
through programs similar to TOAD or SQL Server Management Studio)
• SQL statement scripting
• SSRS – creation, modification, .net programing
 Experience in the development/support of client/server applications, web 
applications using ASP.NET, ASP, C#, VB.NET, writing stored procedures in SQL 
server 2008 and/or Oracle 10/11 is desirable.
o Applications: (must have experience on 3-4 applications out of 8 mentioned 
below)
 Meridium
 KMS
 E3 VMSDS
 IULCID
 SAP PS Configuration (Report Shipping, Templates, GLM, SAP WWI, SDSWeb 
interface, SAP CLEO Content, SVT, MSDS Maker, OCC, DG, ect.)
 Medgate(IH/OH)
 Stature
 PHA PRO
 
Thanks & Regards 
   
Sourav Paul | Technical Recruiter

IT–SCIENT LLC, Fremont, CA, USA  
Email: [email protected]
Phone: 510-972-8633 | Fax: 877-701-5240
|web: www.itscient.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: Anyone here use the ConEmu console app?

2016-04-11 Thread DFS

On 4/11/2016 6:04 PM, 20/20 Lab wrote:

win+alt+space does not work?  ctrl+alt+win+space?

http://conemu.github.io/en/KeyboardShortcuts.html

Says those are not configurable, so they should work.



Neither of those worked, but Ctrl+~ did.

Thankyouthankyouthankyou




On 04/11/2016 02:49 PM, DFS wrote:

I turned on the Quake-style option (and auto-hide when it loses focus)
and it disappeared and I can't figure out how to get it back onscreen.
I think there's a keystroke combo (like Win+key) but I don't know what
it is.

It shows in the Task Manager Processses, but not in the Alt+Tab list.

Uninstalled and reinstalled and now it launches Quake-style and
hidden.  Looked everywhere (\Users\AppData\Local, Registry) for
leftover settings file but couldn't find it.

Here's the screen where you make the Quake-style setting.
https://conemu.github.io/en/SettingsAppearance.html



Thanks




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


Please use the Python Job Board for recruitment (was: !! Immediate Position:Technical Consultant at (The Woodlands, TX) !!)

2016-04-11 Thread Ben Finney
[email protected] writes:

> Please go through the below job description and let me know your interest.

This forum should not be used for job seeking or recruitment.

Please use the Python Job Board, which exists specifically for that
https://www.python.org/jobs/>.

-- 
 \ “Don't be afraid of missing opportunities. Behind every failure |
  `\ is an opportunity somebody wishes they had missed.” —Jane |
_o__)  Wagner, via Lily Tomlin |
Ben Finney 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: REMOVE ME

2016-04-11 Thread Chris Angelico
On Tue, Apr 12, 2016 at 9:10 AM, Steven D'Aprano  wrote:
> Hence "self.things" will return the same
> list each time, the one defined as a class attribute, regardless of
> which "self" does the lookup.
>
> If a method were to assign to the attribute, for example "self.things = []",
> that would create an instance attribute, but that doesn't happen.

Indeed. And the __del__ method is guaranteed always to raise an
exception; by the time __del__ gets called, there can't be any
references to the object anywhere, so it can't be in that list any
more...

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


Re: Python,ping,csv

2016-04-11 Thread Jason Friedman
> I added a line.
> I would need to put the output into a csv file which contained the results
> of the hosts up and down.
> Can you help me?
>
>
> import subprocess
> from ipaddress import IPv4Network
> for address in IPv4Network('10.24.59.0/24').hosts():
> a = str(address)
> res = subprocess.call(['ping', '-c', '3', address])

"""Typical output from ping:

$ ping -c 3 10.2.2.2
PING 10.2.2.2 (10.2.2.2) 56(84) bytes of data.

--- 10.2.2.2 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms


$ ping -c 3 localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.030 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.042 ms

--- localhost ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.030/0.037/0.042/0.007 ms
"""

import csv
import ipaddress
import re
import subprocess
import sys
NETWORK = "192.168.1.0"
MASK = "24"
with open('some.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(("Address", "% success"))
for address in ipaddress.IPv4Network('%s/%s' % (NETWORK, MASK)).hosts():
print("Pinging %s ..." % address, file=sys.stderr)
command = "ping -c 3 %s" % address
output = subprocess.getoutput(command)
match = re.search(r"(\d+)% packet loss", output)
if match:
percent_lost = match.group(1)
writer.writerow((str(address), 100 - int(percent_lost)))
else:
# If we reach this point the ping command output
# was not in the expected output format
writer.writerow((str(address), ""))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python,ping,csv

2016-04-11 Thread Jason Friedman
> I added a line.
> I would need to put the output into a csv file which contained the 
> results of the hosts up and down.
> Can you help me?
> 
> import subprocess
> from ipaddress import IPv4Network
> for address in IPv4Network('10.24.59.0/24').hosts():
>   a = str(address)
>   res = subprocess.call(['ping', '-c', '3', address])
> 

"""Typical output from ping:

$ ping -c 3 10.2.2.2
PING 10.2.2.2 (10.2.2.2) 56(84) bytes of data.

--- 10.2.2.2 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms


$ ping -c 3 localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.030 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.042 ms

--- localhost ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.030/0.037/0.042/0.007 ms
"""

import csv
import ipaddress
import re
import subprocess
import sys
NETWORK = "192.168.1.0"
MASK = "24"
with open('some.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(("Address", "% success"))
for address in ipaddress.IPv4Network('%s/%s' % (NETWORK, 
MASK)).hosts():
print("Pinging %s ..." % address, file=sys.stderr)
command = "ping -c 3 %s" % address
output = subprocess.getoutput(command)
match = re.search(r"(\d+)% packet loss", output)
if match:
percent_lost = match.group(1)
writer.writerow((str(address), 100 - int(percent_lost)))
else:
# If we reach this point the ping command output
# was not in the expected output format
writer.writerow((str(address), ""))





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


Re: one-element tuples

2016-04-11 Thread Larry Hudson via Python-list

On 04/10/2016 08:19 PM, Fillmore wrote:


Thank you for trying to help, Martin. So:

On 04/10/2016 09:08 PM, Martin A. Brown wrote:

#1: I would not choose eval() except when there is no other
 solution.  If you don't need eval(), it may save you some
 headache in the future, as well, to find an alternate way.
 So, can we help you choose something other than eval()?
 What are you trying to do with that usage?


so, I do not quite control the format of the file I am trying to parse.

it has the format:

"str1","str2",,"strN" => more stuff
   :

in some cases there is just one "str" which is what created me problem.
The first "str1" has special meaning and, at times, it can be alone.

The way I handle this is:

 parts = line.strip().split(" => ")
 tokens = eval(parts[0])



[code deleted...]


which admittedly is not very elegant. If you have suggestions on how to avoid 
the use
of eval() and still achieve the same, I would be delighted to hear them




Here is a possible alternate approach to get you started thinking in a 
different direction...

Assuming your input string format is always as you describe, splitting off the trailing 'noise' 
can be done the way you are already doing.  It can be done other ways as well.  (Of course, for 
a 'real' program you will probably need to verify this assumption and take appropriate action if 
necessary.)


parts = line.strip().split(' => ')[0]

Note that this trailing index of 0 will throw away the trailing junk, and leave just the initial 
part of the original line as a string.  This can then be split on the commas to give you a list 
of strings...


tokens = parts.split(',')

This will give you, for example,

['"str1"']   #  Case 1, or
['"str1"', '"str2"', '"str3"', ...]  #  Case 2

There is still a problem here.  The strings CONTAIN beginning and ending quotes INSIDE the 
strings.  We can strip these internal quotes with slicing.  I'm also using a list comprehension 
here...


tokens = [st[1:-1] for st in tokens]

Which gives:  ['str1', 'str2', 'str3', ...]

Finally, there are at least two ways of splitting off the first string:  
slicing or pop().

key = tokens[0]; tokens = tokens[1:]
or
key = tokens.pop(0)#  This simultaneously removes the first string from the 
tokens list

Where key is the first string, and tokens is a list of the remaining strings.  This list may be 
empty.  You can now use the key for whatever you need it for, and you can use a for loop for the 
remaining strings.  Note that this also works correctly for an empty list -- where it will do 
nothing.


I hope this gets you started reworking (or re-thinking) your program.

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