Re: Catogorising strings into random versus non-random

2015-12-21 Thread Peter Otten
Steven D'Aprano wrote:

> I have a large number of strings (originally file names) which tend to
> fall into two groups. Some are human-meaningful, but not necessarily
> dictionary words e.g.:
> 
> 
> baby lions at play
> saturday_morning12
> Fukushima
> ImpossibleFork
> 
> 
> (note that some use underscores, others spaces, and some CamelCase) while
> others are completely meaningless (or mostly so):
> 
> 
> xy39mGWbosjY
> 9sjz7s8198ghwt
> rz4sdko-28dbRW00u
> 
> 
> Let's call the second group "random" and the first "non-random", without
> getting bogged down into arguments about whether they are really random or
> not. I wish to process the strings and automatically determine whether
> each string is random or not. I need to split the strings into three
> groups:
> 
> - those that I'm confident are random
> - those that I'm unsure about
> - those that I'm confident are non-random
> 
> Ideally, I'll get some sort of numeric score so I can tweak where the
> boundaries fall.
> 
> Strings are *mostly* ASCII but may include a few non-ASCII characters.
> 
> Note that false positives (detecting a meaningful non-random string as
> random) is worse for me than false negatives (miscategorising a random
> string as non-random).
> 
> Does anyone have any suggestions for how to do this? Preferably something
> already existing. I have some thoughts and/or questions:
> 
> - I think nltk has a "language detection" function, would that be
> suitable?
> 
> - If not nltk, are there are suitable language detection libraries?
> 
> - Is this the sort of problem that neural networks are good at solving?
> Anyone know a really good tutorial for neural networks in Python?
> 
> - How about Bayesian filters, e.g. SpamBayes?

A dead simple approach -- look at the pairs in real words and calculate the 
ratio

pairs-also-found-in-real-words/num-pairs

$ cat score.py
import sys
WORDLIST = "/usr/share/dict/words"

SAMPLE = """\
baby lions at play
saturday_morning12
Fukushima
ImpossibleFork
xy39mGWbosjY
9sjz7s8198ghwt
rz4sdko-28dbRW00u
""".splitlines()

def extract_pairs(text):
for i in range(len(text)-1):
yield text[i:i+2]


def load_pairs():
pairs = set()
with open(WORDLIST) as f:
for line in f:
pairs.update(extract_pairs(line.strip()))
return pairs


def get_score(text, popular_pairs):
m = 0
for i, p in enumerate(extract_pairs(text), 1):
if p in popular_pairs:
m += 1
return m/i


def main():
popular_pairs = load_pairs()
for text in sys.argv[1:] or SAMPLE:
score = get_score(text, popular_pairs)
print("%4.2f  %s" % (score, text))


if __name__ == "__main__":
main()

$ python3 score.py
0.65  baby lions at play
0.76  saturday_morning12
1.00  Fukushima
0.92  ImpossibleFork
0.36  xy39mGWbosjY
0.31  9sjz7s8198ghwt
0.31  rz4sdko-28dbRW00u

However:

$ python3 -c 'import random, sys; a = list(sys.argv[1]); random.shuffle(a); 
print("".join(a))' 'baby lions at play'
bnsip atl ayba loy
$ python3 score.py 'bnsip atl ayba loy'
0.65  bnsip atl ayba loy


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


Re: Categorising strings on meaningful–meaningless spectrum (was: Catogorising strings into random versus non-random)

2015-12-21 Thread Steven D'Aprano
On Monday 21 December 2015 14:45, Ben Finney wrote:

> Steven D'Aprano  writes:
> 
>> Let's call the second group "random" and the first "non-random",
>> without getting bogged down into arguments about whether they are
>> really random or not.
> 
> I think we should discuss it, even at risk of getting bogged down. As
> you know better than I, “random” is not an observable property of the
> value, but of the process that produced it.
> 
> So, I don't think “random” is at all helpful as a descriptor of the
> criteria you need for discriminating these values.
> 
> Can you give a better definition of what criteria distinguish the
> values, based only on their observable properties?

No, not really. This *literally* is a case of "I'll know it when I see it", 
which suggests that some sort of machine-learning solution (neural network?) 
may be useful. I can train it on a bunch of strings which I can hand-
classify, and let the machine pick out the correlations, then apply it to 
the rest of the strings.

The best I can say is that the "non-random" strings either are, or consist 
of, mostly English words, names, or things which look like they might be 
English words, containing no more than a few non-ASCII characters, 
punctuation, or digits.


> You used “meaningless”; that seems at least more hopeful as a criterion
> we can use by examining text values. So, what counts as meaningless?

Strings made up of random-looking sequences of characters, like you often 
see on sites like imgur or tumblr. Characters from non-Latin character sets 
that I can't read (e.g. Japanese, Korean, Arabic, etc). Jumbled up words, 
e.g. "python" is non-random, "nyohtp" would be random.


[...]
> Perhaps you could measure Shannon entropy (“expected information value”)
> https://en.wikipedia.org/wiki/Entropy_%28information_theory%29> as
> a proxy? Or maybe I don't quite understand the criteria.

That's a possibility. At least, it might be able to distinguish some 
strings, although if I understand correctly, the two strings "python" and 
"nhoypt" have identical entropy, so this alone won't be sufficient.




-- 
Steve

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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Steven D'Aprano
On Monday 21 December 2015 15:22, Chris Angelico wrote:

> On Mon, Dec 21, 2015 at 2:01 PM, Steven D'Aprano 
> wrote:
>> I have a large number of strings (originally file names) which tend to
>> fall into two groups. Some are human-meaningful, but not necessarily
>> dictionary words e.g.:
[...]

> The first thing that comes to my mind is poking the string into a
> search engine and seeing how many results come back. You might need to
> do some preprocessing to recognize multi-word forms (maybe a handful
> of recognized cases like snake_case, CamelCase,
> CamelCasewiththeLittleWordsLeftUnchanged, etc),

I could possibly split the string into "words", based on CamelCase, spaces, 
hyphens or underscores. That would cover most of the cases.

> How many of these keywords would you be looking up, and would a
> network transaction (a search engine API call) for each one be too
> expensive?

Tens or hundreds of thousands of strings, and yes a network transaction 
probably would be a bit much. I'd rather not have Google or Bing be a 
dependency :-)


-- 
Steve

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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Christian Gollwitzer

Am 21.12.15 um 09:24 schrieb Peter Otten:

Steven D'Aprano wrote:


I have a large number of strings (originally file names) which tend to
fall into two groups. Some are human-meaningful, but not necessarily
dictionary words e.g.:


baby lions at play
saturday_morning12
Fukushima
ImpossibleFork


(note that some use underscores, others spaces, and some CamelCase) while
others are completely meaningless (or mostly so):


xy39mGWbosjY
9sjz7s8198ghwt
rz4sdko-28dbRW00u


Let's call the second group "random" and the first "non-random", without
getting bogged down into arguments about whether they are really random or
not. I wish to process the strings and automatically determine whether
each string is random or not. I need to split the strings into three
groups:

- those that I'm confident are random
- those that I'm unsure about
- those that I'm confident are non-random

Ideally, I'll get some sort of numeric score so I can tweak where the
boundaries fall.

Strings are *mostly* ASCII but may include a few non-ASCII characters.

Note that false positives (detecting a meaningful non-random string as
random) is worse for me than false negatives (miscategorising a random
string as non-random).

Does anyone have any suggestions for how to do this? Preferably something
already existing. I have some thoughts and/or questions:

- I think nltk has a "language detection" function, would that be
suitable?

- If not nltk, are there are suitable language detection libraries?

- Is this the sort of problem that neural networks are good at solving?
Anyone know a really good tutorial for neural networks in Python?

- How about Bayesian filters, e.g. SpamBayes?


A dead simple approach -- look at the pairs in real words and calculate the
ratio

pairs-also-found-in-real-words/num-pairs


Sounds reasonable. Building on this approach, two simple improvements:
- calculate the log-likelihood instead, which also makes use of the 
frequency of the digraphs in the training set

- Use trigraphs instead of digraphs
- preprocess the string (lowercase), but more sophisticated 
preprocessing could be an option (i.e. converting under_scores and 
CamelCase to spaces)


The main reason for the low score of the baby lions is the space 
character, I think - the word list does not contain that much spaces. 
Maybe one should feed in some long wikipedia article to calculate the 
digraph/trigraph probabilities


=
Apfelkiste:Tests chris$ cat score_my.py
from __future__ import division
from collections import Counter, defaultdict
from math import log
import sys
WORDLIST = "/usr/share/dict/words"

SAMPLE = """\
baby lions at play
saturday_morning12
Fukushima
ImpossibleFork
xy39mGWbosjY
9sjz7s8198ghwt
rz4sdko-28dbRW00u
""".splitlines()

def extract_pairs(text):
for i in range(len(text)-1):
yield text.lower()[i:i+2]
# or len(text)-2 and i:i+3


def load_pairs():
pairs = Counter()
with open(WORDLIST) as f:
for line in f:
pairs.update(extract_pairs(line.strip()))
# normalize to sum
total_count = sum([pairs[x] for x in pairs])
N = total_count+len(pairs)
dist = defaultdict(lambda:1/N, ((x, (pairs[x]+1)/N) for x in pairs))
return dist


def get_score(text, dist):
ll= 0
for i, x in enumerate(extract_pairs(text), 1):
ll += log(dist[x])
return ll / i


def main():
pair_dist = load_pairs()
for text in sys.argv[1:] or SAMPLE:
score = get_score(text, pair_dist)
print("%.3g  %s" % (score, text))


if __name__ == "__main__":
main()

Apfelkiste:Tests chris$ python score_my.py
-8.74  baby lions at play
-7.63  saturday_morning12
-6.38  Fukushima
-5.72  ImpossibleFork
-10.6  xy39mGWbosjY
-12.9  9sjz7s8198ghwt
-12.1  rz4sdko-28dbRW00u
Apfelkiste:Tests chris$ python score_my.py 'bnsip atl ayba loy'
-9.43  bnsip atl ayba loy
Apfelkiste:Tests chris$

and using trigraphs:

Apfelkiste:Tests chris$ python score_my.py 'bnsip atl ayba loy'
-12.5  bnsip atl ayba loy
Apfelkiste:Tests chris$ python score_my.py
-11.5  baby lions at play
-9.88  saturday_morning12
-9.85  Fukushima
-7.68  ImpossibleFork
-13.4  xy39mGWbosjY
-14.2  9sjz7s8198ghwt
-14.2  rz4sdko-28dbRW00u
==

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


Re: Python 3.1 test issue

2015-12-21 Thread rakeshravinlr
On Wednesday, December 16, 2015 at 11:53:14 PM UTC+5:30, George Trojan wrote:
> I installed Python 3.1 on RHEL 7.2.  The command make test hangs (or 
> takes a lot of time) on test_subprocess.
> 
> [396/397] test_subprocess
> ^C
> Test suite interrupted by signal SIGINT.
> 5 tests omitted:
>  test___all__ test_distutils test_site test_socket test_warnings
> 381 tests OK.
> 4 tests altered the execution environment:
>  test___all__ test_distutils test_site test_warnings
> 11 tests skipped:
>  test_devpoll test_kqueue test_msilib test_ossaudiodev
>  test_startfile test_tix test_tk test_ttk_guionly test_winreg
>  test_winsound test_zipfile64
> make: *** [test] Error 1
> 
> CPU was at 100% all the time for process
> 
> gtrojan  15758  8907 94 17:29 pts/6 00:06:47 
> /home/gtrojan/Downloads/Python-3.5.1/python -R -bb -E -Wdefault 
> -Werror::BytesWarning -X faulthandler -m test.regrtest --slaveargs 
> [["test_socket", 0, false], {"huntrleaks": false, "match_tests": null, 
> "failfast": false, "output_on_failure": false, "use_resources": 
> ["curses", "network", "decimal", "cpu", "subprocess", "urlfetch"], 
> "pgo": false, "timeout": null}]
> gtrojan  22889   336  0 17:36 pts/11   00:00:00 grep --color=auto 15758
> 
> Is this a problem?
> 
> George

can u help me to convert the folowing test case

Input:
/home/rebaca/azuki/streams/./tsudpsend 
/home/rebaca/azuki/streams/ebp/ebp-1250-2.ts 127.0.0.1 500011 
2151832|/home/rebaca/azuki/streams/./tsudpsend 
/home/rebaca/azuki/streams/ebp/ebp-1251-2.ts 127.0.0.1 500012 
2151832|/home/rebaca/azuki/streams/./tsudpsend 
/home/rebaca/azuki/streams/ebp/ebp-1250-2.ts 127.0.0.1 500013 2151832



Output:

AZ_HLS_PORT_BASED_VOD_TC6_STL_CMD='{ "TSUDPSEND":[ { "ebp_1250_2_av":"tsudpsend 
'+ STREAMS_PATH +'/ebp/ebp-1250-2.ts '+ DEVICE_UNDER_TEST +'5000112151832" }, { 
"ebp_1250_2_v": "tsudpsend '+ STREAMS_PATH+'/ebp/ebp-1250-2.ts '+ 
DEVICE_UNDER_TEST +' 500012 2151832" },{"ebp_1250_2_a": "tsudpsend '+ 
STREAMS_PATH +'/ebp/ebp-1250-2.ts '+DEVICE_UNDER_TEST +' 500013 2151832" } ] }' 


how to get output in the following format when the input is given using python



# The following are commands used for pumping the streams.
"/home/rebaca/azuki/streams/./tsudpsend"==> this is the path of the tool
used for pumping streams.
# "/home/rebaca/azuki/streams/ebp/ebp-1250-2.ts" ==>  Stream Path
# "127.0.0.1" & "500011" ==> Device IP & Port, respectively, to which
the stream needs to be pumped.
# "2151832" ==> Overall Bitrate of the input stream. 



please help me if u can
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Steven D'Aprano
On Mon, 21 Dec 2015 08:56 pm, Christian Gollwitzer wrote:

> Apfelkiste:Tests chris$ python score_my.py
> -8.74  baby lions at play
> -7.63  saturday_morning12
> -6.38  Fukushima
> -5.72  ImpossibleFork
> -10.6  xy39mGWbosjY
> -12.9  9sjz7s8198ghwt
> -12.1  rz4sdko-28dbRW00u
> Apfelkiste:Tests chris$ python score_my.py 'bnsip atl ayba loy'
> -9.43  bnsip atl ayba loy

Thanks Christian and Peter for the suggestion, I'll certainly investigate
this further.

But the scoring doesn't seem very good. "baby lions at play" is 100% English
words, and ought to have a radically different score from (say)
xy39mGWbosjY which is extremely non-English like. (How many English words
do you know of with W, X, two Y, and J?) And yet they are only two units
apart. "baby lions..." is a score almost as negative as the authentic
gibberish, while Fukushima (a Japanese word) has a much less negative
score. Using trigraphs doesn't change that:

> -11.5  baby lions at play
> -9.85  Fukushima
> -13.4  xy39mGWbosjY

So this test appears to find that English-like words are nearly as "random"
as actual random strings.

But it's certainly worth looking into.


-- 
Steven

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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Christian Gollwitzer

Am 21.12.15 um 11:36 schrieb Steven D'Aprano:

On Mon, 21 Dec 2015 08:56 pm, Christian Gollwitzer wrote:


Apfelkiste:Tests chris$ python score_my.py
-8.74  baby lions at play
-7.63  saturday_morning12
-6.38  Fukushima
-5.72  ImpossibleFork
-10.6  xy39mGWbosjY
-12.9  9sjz7s8198ghwt
-12.1  rz4sdko-28dbRW00u
Apfelkiste:Tests chris$ python score_my.py 'bnsip atl ayba loy'
-9.43  bnsip atl ayba loy


Thanks Christian and Peter for the suggestion, I'll certainly investigate
this further.

But the scoring doesn't seem very good. "baby lions at play" is 100% English
words, and ought to have a radically different score from (say)
xy39mGWbosjY which is extremely non-English like. (How many English words
do you know of with W, X, two Y, and J?) And yet they are only two units
apart. "baby lions..." is a score almost as negative as the authentic
gibberish, while Fukushima (a Japanese word) has a much less negative
score.


It is the spaces, which do not occur in the training wordlist (I 
mentioned that above, maybe not prominently enough). 
/usr/share/dict/words contains one word per line. The underscore _ is 
probably putting the saturday morning low, while the spaces put the 
babies low. Using trigraphs:



Apfelkiste:Tests chris$ python score_my.py
-11.5  baby lions at play
-9.88  saturday_morning12
-9.85  Fukushima
-7.68  ImpossibleFork
-13.4  xy39mGWbosjY
-14.2  9sjz7s8198ghwt
-14.2  rz4sdko-28dbRW00u
Apfelkiste:Tests chris$ python score_my.py 'babylionsatplay'
-8.74  babylionsatplay
Apfelkiste:Tests chris$ python score_my.py 'saturdaymorning12'
-8.93  saturdaymorning12
Apfelkiste:Tests chris$

So for the spaces, either use a proper trainig material (some long 
corpus from Wikipedia or such), with punctuation removed. Then it will 
catch the correct probabilities at word boundaries. Or preprocess by 
removing the spaces.


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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Christian Gollwitzer

Am 21.12.15 um 11:53 schrieb Christian Gollwitzer:

So for the spaces, either use a proper trainig material (some long
corpus from Wikipedia or such), with punctuation removed. Then it will
catch the correct probabilities at word boundaries. Or preprocess by
removing the spaces.

 Christian


PS: The real log-likelihood would become -infinity, when some pair does 
not appear at all in the training set (esp. the numbers, e.g.). I used 
the 1/total in the defaultdict to mitigate that. You could tweak that 
value a bit. The larger the corpus, the sharper it will divide by 
itself, too.


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


[no subject]

2015-12-21 Thread Animesh Srivastava
While installin python3.5.1 i m getting 0xc07b error
Please reslove it
-- 
https://mail.python.org/mailman/listinfo/python-list


Please help

2015-12-21 Thread Abdul Basit
I am receiving this error while installing python interpreter version 3.5.1 (32 
bit)
Error is " This program cannot start because api-ms-win-crt-runtime-l1-1-0.dll 
is missing from your computer"

I reinstalled this file but again this error message 

What should I do to remove this issue kindly help me 

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


IDLE 3.5.1 quits unexpectedly (portuguese keyboard)

2015-12-21 Thread Osvaldo Dias dos Santos
Hi,

Pressing the tilde key my iMac portuguese keyboard quits IDLE unexpectedly 
(along with any associated files I may be working on, including code). 

The keyboard image is attached. The tilde key is the second orange one from the 
top.

This key is very important in this language, because pressing it together with 
the shift key, the caret ( ^ ) symbol is entered. So, if I try to enter a caret 
and press the shift and the tilde key to do it, IDLE quits and any unsaved file 
information (even code) is lost.
Then Apple crash report window opens, but if I click the reopen button nothing 
happens, IDLE does not reopen.

Python 3.5.1
OS X 10.11.2 (El Capitan)

Anyone may help ?

Thank you,
Kind regards,
Osvaldo


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


v3.5.1 - msi download

2015-12-21 Thread Renato Emanuel Dysangco
hello

is an **.msi* version of your *Python 3.5.1 (32 bit)* in the pipeline soon?

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


Error

2015-12-21 Thread Amaan Hussain
Hello.
I get an error saying "api-ms-win-crt-runtime-l1-1-0.dll is missing"
Can you tell me how to fix this.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


return from function

2015-12-21 Thread Emil Natan
I'm completely new to Python.
I have the following function to find the parent for domain. It removes the
left most label from the name and then checks if SOA record exists for the
reminder, if not it calls itself recursively removing another label and
checking again for SOA record. It works well for 'co.uk' and 'amazon.co.uk'
for example. It does not return the expected value 'uk' when invoked for '
amazon1.co1.uk', though the print command before the return prints what is
expected. Can someone explain why? Thanks.

>>> find_parent_domain('amazon.co1.uk.')
Test for parent domain co1.uk.
NXDOMAIN: invoke find_parent_domain recursively
Test for parent domain uk.
the parent domain we use is: uk.
>>>

import dns.resolver
from dns.exception import DNSException

def find_parent_domain(domainname):

if domainname == '.':
parent_domain = None
return parent_domain

parent_domain = domainname.partition('.')[2]
try:
print('Test for parent domain %s' % parent_domain)
z = dns.resolver.query(parent_domain, 'SOA')
print('the parent domain we use is: %s' % parent_domain)
return parent_domain
except dns.resolver.NXDOMAIN:
print('NXDOMAIN: invoke find_parent_domain recursively')
find_parent_domain(parent_domain)
except dns.resolver.NoAnswer:
print('NoAnswer: invoke find_parent_domain recursively')
find_parent_domain(parent_domain)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: return from function

2015-12-21 Thread Jon Ribbens
On 2015-12-20, Emil Natan  wrote:
> I have the following function to find the parent for domain. It removes the
> left most label from the name and then checks if SOA record exists for the
> reminder, if not it calls itself recursively removing another label and
> checking again for SOA record. It works well for 'co.uk' and 'amazon.co.uk'
> for example. It does not return the expected value 'uk' when invoked for '
> amazon1.co1.uk', though the print command before the return prints what is
> expected. Can someone explain why? Thanks.

You probably want to look at this: https://publicsuffix.org/

> except dns.resolver.NXDOMAIN:
> print('NXDOMAIN: invoke find_parent_domain recursively')
> find_parent_domain(parent_domain)

  return find_parent_domain(parent_domain)

> except dns.resolver.NoAnswer:
> print('NoAnswer: invoke find_parent_domain recursively')
> find_parent_domain(parent_domain)

  return find_parent_domain(parent_domain)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-21 Thread Skybuck Flying
The original idea I posted is less about sending a signal to another 
processor.


It is more about how to break out of an instruction sequence.

Example of problem:

Main:
while Condition1 do
begin
   while Condition2 do
   begin
   while Condition3 do
   begin
   Routine1
   end
   end;
end;

Routine1:

while Condition4 do
begin
   while Condition5 do
   begin
   Routine2:
   end;
end;

Routine2:

while Condition6 do
begin
   while Condition7 do
   begin

   end;
end;

Breaking out of these kinds of loops, routines, code currently requires 
something like:


Current cumbersome solution for problem:

Main:
while Condition1 and not Terminated do
begin
   while Condition2 and not Terminated do
   begin
   while Condition3 and not Terminated do
   begin
   Routine1
   end
   end;
end;

Routine1:

while Condition4 and not Terminated do
begin
   while Condition5 and not Terminated do
   begin
   Routine2:
   end;
end;

Routine2:

while Condition6 and not Terminated do
begin
   while Condition7 and not Terminated do
   begin

   end;
end;

It can take a long while before all this code exits, plus the Terminated 
boolean is probably placed on wrong side.


It should be on the left side in case the Conditions are actual functions 
otherwise those would unnecessarily be executed as well.


Having something that can immediatly exit all of this code would be a nice 
feature to have.


Perhaps something like an exception block, perhaps it could be called a 
termination block.


Routine1:
Result = False

Execute
   while True do
   begin

   end;
   Result = True
Termination
   OnTerminate:
   begin

   end;
end;

return Result

Preferrably , optionally this can be omitted/left out.

Bye,
 Skybuck. 


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


Re: v3.5.1 - msi download

2015-12-21 Thread Mark Lawrence

On 19/12/2015 17:45, Renato Emanuel Dysangco wrote:

hello

is an **.msi* version of your *Python 3.5.1 (32 bit)* in the pipeline soon?

thanks for your time



msi files are not being made available for 3.5.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Ignore error with non-zero exit status

2015-12-21 Thread Mark Lawrence

On 21/12/2015 07:51, Thomas 'PointedEars' Lahn wrote:

Chris Angelico wrote:


But it's been clearly stated that .format is not going to do away with
percent formatting, and all language of "new-style formatting" has been
removed so as not to cause confusion.


Wishful thinking, twice.



http://www.gossamer-threads.com/lists/python/dev/969817

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Ignore error with non-zero exit status

2015-12-21 Thread Thomas 'PointedEars' Lahn
Mark Lawrence wrote:

> On 21/12/2015 07:51, Thomas 'PointedEars' Lahn wrote:
>> Chris Angelico wrote:
>>> But it's been clearly stated that .format is not going to do away with
>>> percent formatting, and all language of "new-style formatting" has been
>>> removed so as not to cause confusion.
>>
>> Wishful thinking, twice.
> 
> http://www.gossamer-threads.com/lists/python/dev/969817

What is this supposed to be evidence of?

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ignore error with non-zero exit status

2015-12-21 Thread Chris Angelico
On Tue, Dec 22, 2015 at 12:19 AM, Thomas 'PointedEars' Lahn
 wrote:
> Mark Lawrence wrote:
>
>> On 21/12/2015 07:51, Thomas 'PointedEars' Lahn wrote:
>>> Chris Angelico wrote:
 But it's been clearly stated that .format is not going to do away with
 percent formatting, and all language of "new-style formatting" has been
 removed so as not to cause confusion.
>>>
>>> Wishful thinking, twice.
>>
>> http://www.gossamer-threads.com/lists/python/dev/969817
>
> What is this supposed to be evidence of?

Proof that percent formatting isn't planned for deprecation, much less
removal. There is strong support for it in certain quarters of
python-dev. It's a fully supported language feature, not an old and
outmoded feature that is kept solely for backward compatibility (as
"old-style classes" are in Python 2.7 - you can still use them, but as
of Python 3, only "new-style classes" exist).

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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Vlastimil Brom
2015-12-21 4:01 GMT+01:00 Steven D'Aprano :
> I have a large number of strings (originally file names) which tend to fall
> into two groups. Some are human-meaningful, but not necessarily dictionary
> words e.g.:
>
>
> baby lions at play
> saturday_morning12
> Fukushima
> ImpossibleFork
>
>
> (note that some use underscores, others spaces, and some CamelCase) while
> others are completely meaningless (or mostly so):
>
>
> xy39mGWbosjY
> 9sjz7s8198ghwt
> rz4sdko-28dbRW00u
>
>
> Let's call the second group "random" and the first "non-random", without
> getting bogged down into arguments about whether they are really random or
> not. I wish to process the strings and automatically determine whether each
> string is random or not. I need to split the strings into three groups:
>
> - those that I'm confident are random
> - those that I'm unsure about
> - those that I'm confident are non-random
>
> Ideally, I'll get some sort of numeric score so I can tweak where the
> boundaries fall.
>
> Strings are *mostly* ASCII but may include a few non-ASCII characters.
>
> Note that false positives (detecting a meaningful non-random string as
> random) is worse for me than false negatives (miscategorising a random
> string as non-random).
>
> Does anyone have any suggestions for how to do this? Preferably something
> already existing. I have some thoughts and/or questions:
>
> - I think nltk has a "language detection" function, would that be suitable?
>
> - If not nltk, are there are suitable language detection libraries?
>
> - Is this the sort of problem that neural networks are good at solving?
> Anyone know a really good tutorial for neural networks in Python?
>
> - How about Bayesian filters, e.g. SpamBayes?
>
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
as you probably already know, NLTK could be helpful for some parts of
this task; if you can handle the most likely "word" splitting involved
by underscores, CamelCase etc., you could try to tag the parts of
speech of the words and interpret for the results according to your
needs.
In the online demo
http://text-processing.com/demo/tag/
your sample (with different approaches to splitt the words) yields:

baby/NN lions/NNS at/IN play/VB saturday/NN morning/NN 12/CD
Fukushima/NNP Impossible/JJ Fork/NNP xy39mGWbosjY/-None-
9sjz7s8198ghwt/-None- rz4sdko/-None- -/: 28dbRW00u/-None-

or with more splittings on case or letter-digit boundaries:
baby/NN lions/NNS at/IN play/VB saturday/NN morning/NN 12/CD
Fukushima/NNP Impossible/JJ Fork/NNP xy/-None- 39/CD m/-None- G/NNP
Wbosj/-None- Y/-None- 9/CD sjz/-None- 7/CD s/-None- 8198/-NONE-
ghwt/-None- rz/-None- 4/CD sdko/-None- -/: 28/CD db/-None- R/NNP
W/-None- 00/-None- u/-None-

 the tagset might be compatible with
https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html

There is sample code with a comparable output to this demo:
http://stackoverflow.com/questions/23953709/how-do-i-tag-a-sentence-with-the-brown-or-conll2000-tagger-chunker

For the given minimal sample, the results look useful (maybe with
exception of the capitalised words sometimes tagged as proper names -
but it might not be that relevant here).
Of course, any scoring isn't available with this approach, but you
could maybe check the proportion of the  recognised "words" comparing
to the total number of the "words" for the respective filename.
Training the tagger should be possible too in NLTK, but I don't have
experiences with this.

regards,
 vbr
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Vincent Davis
On Mon, Dec 21, 2015 at 7:25 AM, Vlastimil Brom 
wrote:

> > baby lions at play
> > saturday_morning12
> > Fukushima
> > ImpossibleFork
> >
> >
> > (note that some use underscores, others spaces, and some CamelCase) while
> > others are completely meaningless (or mostly so):
> >
> >
> > xy39mGWbosjY
> > 9sjz7s8198ghwt
> > rz4sdko-28dbRW00u
>

My first thought it to search google for each wor
​d​
or phase and count
​(google gives a count) ​
the results. For example if you search for "xy39mGWbosjY" there is one
result as of now,
​which
 is an archive of this tread. If you search for any given word or even the
phrase
​, for example​
"baby lions at play
​
" you get a much larger set of results
​ ~500​
. I assue there are many was to search google with python, this looks like
one. https://pypi.python.org/pypi/google

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


Re: Ignore error with non-zero exit status

2015-12-21 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote:

> On Tue, Dec 22, 2015 at 12:19 AM, Thomas 'PointedEars' Lahn
>  wrote:
>> Mark Lawrence wrote:
>>> On 21/12/2015 07:51, Thomas 'PointedEars' Lahn wrote:
 Chris Angelico wrote:
> But it's been clearly stated that .format is not going to do away with
> percent formatting, and all language of "new-style formatting" has
> been removed so as not to cause confusion.
 Wishful thinking, twice.
>>> http://www.gossamer-threads.com/lists/python/dev/969817
>> What is this supposed to be evidence of?
> 
> Proof that percent formatting isn't planned for deprecation, much less
> removal.

Then it would have failed to accomplish that.

> There is strong support for it in certain quarters of python-dev. […]

There *was*.  The referred thread is from 2012-02.  It is 2015-12.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ignore error with non-zero exit status

2015-12-21 Thread Chris Angelico
On Tue, Dec 22, 2015 at 1:05 AM, Thomas 'PointedEars' Lahn
 wrote:
> Chris Angelico wrote:
>
>> On Tue, Dec 22, 2015 at 12:19 AM, Thomas 'PointedEars' Lahn
>>  wrote:
>>> Mark Lawrence wrote:
 On 21/12/2015 07:51, Thomas 'PointedEars' Lahn wrote:
> Chris Angelico wrote:
>> But it's been clearly stated that .format is not going to do away with
>> percent formatting, and all language of "new-style formatting" has
>> been removed so as not to cause confusion.
> Wishful thinking, twice.
 http://www.gossamer-threads.com/lists/python/dev/969817
>>> What is this supposed to be evidence of?
>>
>> Proof that percent formatting isn't planned for deprecation, much less
>> removal.
>
> Then it would have failed to accomplish that.
>
>> There is strong support for it in certain quarters of python-dev. […]
>
> There *was*.  The referred thread is from 2012-02.  It is 2015-12.

Then show some evidence that python-dev has changed in viewpoint.

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


Re: Ignore error with non-zero exit status

2015-12-21 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote:

> […] Thomas 'PointedEars' Lahn […] wrote:
>> Chris Angelico wrote:
>>> […] Thomas 'PointedEars' Lahn […] wrote:
 Mark Lawrence wrote:
> On 21/12/2015 07:51, Thomas 'PointedEars' Lahn wrote:
>> Chris Angelico wrote:
>>> But it's been clearly stated that .format is not going to do away
>>> with percent formatting, and all language of "new-style formatting"
>>> has been removed so as not to cause confusion.
>> Wishful thinking, twice.
> http://www.gossamer-threads.com/lists/python/dev/969817
 What is this supposed to be evidence of?
>>> Proof that percent formatting isn't planned for deprecation, much less
>>> removal.
>> Then it would have failed to accomplish that.
>> 
>>> There is strong support for it in certain quarters of python-dev. […]
>> There *was*.  The referred thread is from 2012-02.  It is 2015-12.
> 
> Then show some evidence that python-dev has changed in viewpoint.

And why would I do that?  I have claimed no such thing.

Your attempt to shift the burden of proof is unsuccessful.

BTW, which part of “attribution line” did you not understand?

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ignore error with non-zero exit status

2015-12-21 Thread Mark Lawrence

On 21/12/2015 14:19, Thomas 'PointedEars' Lahn wrote:

Chris Angelico wrote:


[…] Thomas 'PointedEars' Lahn […] wrote:

Chris Angelico wrote:

[…] Thomas 'PointedEars' Lahn […] wrote:

Mark Lawrence wrote:

On 21/12/2015 07:51, Thomas 'PointedEars' Lahn wrote:

Chris Angelico wrote:

But it's been clearly stated that .format is not going to do away
with percent formatting, and all language of "new-style formatting"
has been removed so as not to cause confusion.

Wishful thinking, twice.

http://www.gossamer-threads.com/lists/python/dev/969817

What is this supposed to be evidence of?

Proof that percent formatting isn't planned for deprecation, much less
removal.

Then it would have failed to accomplish that.


There is strong support for it in certain quarters of python-dev. […]

There *was*.  The referred thread is from 2012-02.  It is 2015-12.


Then show some evidence that python-dev has changed in viewpoint.


And why would I do that?  I have claimed no such thing.

Your attempt to shift the burden of proof is unsuccessful.

BTW, which part of “attribution line” did you not understand?



Would you please go away as your continued trolling is getting tedious.

TIA.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: v3.5.1 - msi download

2015-12-21 Thread Zachary Ware
On Mon, Dec 21, 2015 at 6:49 AM, Mark Lawrence  wrote:
> On 19/12/2015 17:45, Renato Emanuel Dysangco wrote:
>>
>> hello
>>
>> is an **.msi* version of your *Python 3.5.1 (32 bit)* in the pipeline
>> soon?
>>
>> thanks for your time
>>
>
> msi files are not being made available for 3.5.

Correction: there is no longer a single MSI for everything.  However,
each individual component (e.g. the interpreter, the standard library,
the standard library test suite, Tcl/Tk and IDLE, etc...) is packaged
as an MSI, and all can be downloaded by running the installer as
`.exe /layout some/path/to/hold/the/MSIs`.  The .exe
installer itself also takes many useful command line options, see
https://docs.python.org/3.5/using/windows.html.

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


Re: Ignore error with non-zero exit status

2015-12-21 Thread Random832
Thomas 'PointedEars' Lahn writes:
> Chris Angelico wrote:
CA Proof that percent formatting isn't planned for deprecation, much less
CA removal.
TL>>> Then it would have failed to accomplish that.
CA There is strong support for it in certain quarters of python-dev. […]
TL>>> There *was*.  The referred thread is from 2012-02.  It is 2015-12.
CA>> Then show some evidence that python-dev has changed in viewpoint.
TL> And why would I do that?  I have claimed no such thing.

Yes, you have.  Your claim that evidence from 2012 is no longer
relevant is an implicit claim of precisely that.

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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread duncan smith
On 21/12/15 03:01, Steven D'Aprano wrote:
> I have a large number of strings (originally file names) which tend to fall
> into two groups. Some are human-meaningful, but not necessarily dictionary
> words e.g.:
> 
> 
> baby lions at play
> saturday_morning12
> Fukushima
> ImpossibleFork
> 
> 
> (note that some use underscores, others spaces, and some CamelCase) while
> others are completely meaningless (or mostly so):
> 
> 
> xy39mGWbosjY
> 9sjz7s8198ghwt
> rz4sdko-28dbRW00u
> 
> 
> Let's call the second group "random" and the first "non-random", without
> getting bogged down into arguments about whether they are really random or
> not. I wish to process the strings and automatically determine whether each
> string is random or not. I need to split the strings into three groups:
> 
> - those that I'm confident are random
> - those that I'm unsure about
> - those that I'm confident are non-random
> 
> Ideally, I'll get some sort of numeric score so I can tweak where the
> boundaries fall.
> 
> Strings are *mostly* ASCII but may include a few non-ASCII characters.
> 
> Note that false positives (detecting a meaningful non-random string as
> random) is worse for me than false negatives (miscategorising a random
> string as non-random).
> 
> Does anyone have any suggestions for how to do this? Preferably something
> already existing. I have some thoughts and/or questions:
> 
> - I think nltk has a "language detection" function, would that be suitable?
> 
> - If not nltk, are there are suitable language detection libraries?
> 
> - Is this the sort of problem that neural networks are good at solving?
> Anyone know a really good tutorial for neural networks in Python?
> 
> - How about Bayesian filters, e.g. SpamBayes?
> 
> 
> 
> 

Finite state machine / transition matrix. Learn from some English text
source. Then process your strings by lower casing, replacing underscores
with spaces, removing trailing numeric characters etc. Base your score
on something like the mean transition probability. I'd expect to see two
pretty well separated groups of scores.

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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Ian Kelly
On Mon, Dec 21, 2015 at 9:40 AM, duncan smith  wrote:
> Finite state machine / transition matrix. Learn from some English text
> source. Then process your strings by lower casing, replacing underscores
> with spaces, removing trailing numeric characters etc. Base your score
> on something like the mean transition probability. I'd expect to see two
> pretty well separated groups of scores.

Sounds like a case for a Hidden Markov Model.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Mark Lawrence

On 21/12/2015 16:49, Ian Kelly wrote:

On Mon, Dec 21, 2015 at 9:40 AM, duncan smith  wrote:

Finite state machine / transition matrix. Learn from some English text
source. Then process your strings by lower casing, replacing underscores
with spaces, removing trailing numeric characters etc. Base your score
on something like the mean transition probability. I'd expect to see two
pretty well separated groups of scores.


Sounds like a case for a Hidden Markov Model.



In which case https://pypi.python.org/pypi/Markov/0.1 would seem to be a 
starting point.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


What could cause a plot fail in my code?

2015-12-21 Thread Robert
Hi,

I find a useful code snippet on link:

http://stackoverflow.com/questions/25126444/logistic-regression-in-pymc/34400966#34400966

but it has error on plot function. The error message is as following:
-
%run "C:\Users\rj\pyprj\logic_regression0.py"
[-100%-] 1 of 1 complete in 12.6   
secPlotting beta0
Plotting tau
Plotting betaSalad
Plotting sigma
---
UnboundLocalError Traceback (most recent call last)
C:\Users\pyprj\logic_regression0.py in ()
 34 #m.sample(10, 5, 50)
 35 m.sample(1, 5000, 50)
---> 36 pm.Matplot.plot(m)
 37 import matplotlib.pyplot as plt
 38 #plt.plot(m)

C:\Users\AppData\Local\Enthought\Canopy\User\lib\site- 
packages\pymc\Matplot.pyc in wrapper(pymc_obj, *args, **kwargs)
339 if args:
340 name = '%s_%s' % (args[0], variable.__name__)
--> 341 f(data, name, *args, **kwargs)
342 return
343 except AttributeError:

C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc 
in plot(data, name, format, suffix, path,  common_scale, datarange, new, last, 
rows, num, fontmap, verbose)
453 num=num * 2,
454 last=last,
--> 455 fontmap=fontmap)
456 
457 if last:

C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc 
in wrapper(pymc_obj, *args, **kwargs)
375 
376 # If others fail, assume that raw data is passed
--> 377 f(pymc_obj, *args, **kwargs)
378 
379 wrapper.__doc__ = f.__doc__

C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc 
in histogram(data, name, bins, datarange, format, suffix, path, rows, columns, 
num, last, fontmap, verbose)
576 
577 # Generate histogram
--> 578 hist(data.tolist(), bins, histtype='stepfilled')
579 
580 xlim(datarange)

C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\pyplot.py
 in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, 
orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
   2956   histtype=histtype, align=align, 
orientation=orientation,
   2957   rwidth=rwidth, log=log, color=color, label=label,
-> 2958   stacked=stacked, data=data, **kwargs)
   2959 finally:
   2960 ax.hold(washold)

C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\__init__.py
 in inner(ax, *args, **kwargs)
   1809 warnings.warn(msg % (label_namer, func.__name__),
   1810   RuntimeWarning, stacklevel=2)
-> 1811 return func(ax, *args, **kwargs)
   1812 pre_doc = inner.__doc__
   1813 if pre_doc is None:

C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_axes.py
 in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, 
align, orientation, rwidth, log, color, label, stacked, **kwargs)
   6192 ymin = np.amin(m[m != 0])
   6193 # filter out the 0 height bins
-> 6194 ymin = max(ymin*0.9, minimum) if not input_empty else 
minimum
   6195 ymin = min(ymin0, ymin)
   6196 self.dataLim.intervaly = (ymin, ymax)

UnboundLocalError: local variable 'ymin' referenced before assignment 
/

I have no clue at all on debug it. Could you help me?
Thanks,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Paul Rubin
Steven D'Aprano  writes:
> Does anyone have any suggestions for how to do this? Preferably something
> already existing. I have some thoughts and/or questions:

I think I'd just look at the set of digraphs or trigraphs in each name
and see if there are a lot that aren't found in English.

> - I think nltk has a "language detection" function, would that be suitable?
> - If not nltk, are there are suitable language detection libraries?

I suspect these need longer strings to work.

> - Is this the sort of problem that neural networks are good at solving?
> Anyone know a really good tutorial for neural networks in Python?
> - How about Bayesian filters, e.g. SpamBayes?

You want large training sets for these approaches.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What could cause a plot fail in my code?

2015-12-21 Thread Robert
On Monday, December 21, 2015 at 12:15:54 PM UTC-5, Robert wrote:
> Hi,
> 
> I find a useful code snippet on link:
> 
> http://stackoverflow.com/questions/25126444/logistic-regression-in-pymc/34400966#34400966
> 
> but it has error on plot function. The error message is as following:
> -
> %run "C:\Users\rj\pyprj\logic_regression0.py"
> [-100%-] 1 of 1 complete in 12.6  
>  secPlotting beta0
> Plotting tau
> Plotting betaSalad
> Plotting sigma
> ---
> UnboundLocalError Traceback (most recent call last)
> C:\Users\pyprj\logic_regression0.py in ()
>  34 #m.sample(10, 5, 50)
>  35 m.sample(1, 5000, 50)
> ---> 36 pm.Matplot.plot(m)
>  37 import matplotlib.pyplot as plt
>  38 #plt.plot(m)
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site- 
> packages\pymc\Matplot.pyc in wrapper(pymc_obj, *args, **kwargs)
> 339 if args:
> 340 name = '%s_%s' % (args[0], variable.__name__)
> --> 341 f(data, name, *args, **kwargs)
> 342 return
> 343 except AttributeError:
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc
>  in plot(data, name, format, suffix, path,  common_scale, datarange, new, 
> last, rows, num, fontmap, verbose)
> 453 num=num * 2,
> 454 last=last,
> --> 455 fontmap=fontmap)
> 456 
> 457 if last:
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc
>  in wrapper(pymc_obj, *args, **kwargs)
> 375 
> 376 # If others fail, assume that raw data is passed
> --> 377 f(pymc_obj, *args, **kwargs)
> 378 
> 379 wrapper.__doc__ = f.__doc__
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc
>  in histogram(data, name, bins, datarange, format, suffix, path, rows, 
> columns, num, last, fontmap, verbose)
> 576 
> 577 # Generate histogram
> --> 578 hist(data.tolist(), bins, histtype='stepfilled')
> 579 
> 580 xlim(datarange)
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\pyplot.py
>  in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, 
> align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
>2956   histtype=histtype, align=align, 
> orientation=orientation,
>2957   rwidth=rwidth, log=log, color=color, 
> label=label,
> -> 2958   stacked=stacked, data=data, **kwargs)
>2959 finally:
>2960 ax.hold(washold)
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\__init__.py
>  in inner(ax, *args, **kwargs)
>1809 warnings.warn(msg % (label_namer, func.__name__),
>1810   RuntimeWarning, stacklevel=2)
> -> 1811 return func(ax, *args, **kwargs)
>1812 pre_doc = inner.__doc__
>1813 if pre_doc is None:
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_axes.py
>  in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, 
> align, orientation, rwidth, log, color, label, stacked, **kwargs)
>6192 ymin = np.amin(m[m != 0])
>6193 # filter out the 0 height bins
> -> 6194 ymin = max(ymin*0.9, minimum) if not input_empty else 
> minimum
>6195 ymin = min(ymin0, ymin)
>6196 self.dataLim.intervaly = (ymin, ymax)
> 
> UnboundLocalError: local variable 'ymin' referenced before assignment 
> /
> 
> I have no clue at all on debug it. Could you help me?
> Thanks,

Excuse me. The code link should be this one:

http://nbviewer.ipython.org/gist/aflaxman/8329ec1b9f861469f896

Do you experience such errors?

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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread duncan smith
On 21/12/15 16:49, Ian Kelly wrote:
> On Mon, Dec 21, 2015 at 9:40 AM, duncan smith  wrote:
>> Finite state machine / transition matrix. Learn from some English text
>> source. Then process your strings by lower casing, replacing underscores
>> with spaces, removing trailing numeric characters etc. Base your score
>> on something like the mean transition probability. I'd expect to see two
>> pretty well separated groups of scores.
> 
> Sounds like a case for a Hidden Markov Model.
> 

Perhaps. That would allow the encoding of marginal probabilities and
distinct transition matrices for each class - if we could learn those
extra parameters.

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


Re: What could cause a plot fail in my code?

2015-12-21 Thread Peter Pearson
On Mon, 21 Dec 2015 09:29:24 -0800 (PST), Robert  wrote:
> On Monday, December 21, 2015 at 12:15:54 PM UTC-5, Robert wrote:
>> Hi,
>> 
>> I find a useful code snippet on link:
>> 
>> http://stackoverflow.com/questions/25126444/logistic-regression-in-pymc/34400966#34400966
>> 
>> but it has error on plot function. The error message is as following:
>> -
>> %run "C:\Users\rj\pyprj\logic_regression0.py"
>> [-100%-] 1 of 1 complete in 12.6 
>>   secPlotting beta0
>> Plotting tau
>> Plotting betaSalad
>> Plotting sigma
>> ---
>> UnboundLocalError Traceback (most recent call last)
>> C:\Users\pyprj\logic_regression0.py in ()
>>  34 #m.sample(10, 5, 50)
>>  35 m.sample(1, 5000, 50)
>> ---> 36 pm.Matplot.plot(m)
>>  37 import matplotlib.pyplot as plt
>>  38 #plt.plot(m)
>> 
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site- 
>> packages\pymc\Matplot.pyc in wrapper(pymc_obj, *args, **kwargs)
>> 339 if args:
>> 340 name = '%s_%s' % (args[0], variable.__name__)
>> --> 341 f(data, name, *args, **kwargs)
>> 342 return
>> 343 except AttributeError:
>> 
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc
>>  in plot(data, name, format, suffix, path,  common_scale, datarange, new, 
>> last, rows, num, fontmap, verbose)
>> 453 num=num * 2,
>> 454 last=last,
>> --> 455 fontmap=fontmap)
>> 456 
>> 457 if last:
>> 
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc
>>  in wrapper(pymc_obj, *args, **kwargs)
>> 375 
>> 376 # If others fail, assume that raw data is passed
>> --> 377 f(pymc_obj, *args, **kwargs)
>> 378 
>> 379 wrapper.__doc__ = f.__doc__
>> 
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc
>>  in histogram(data, name, bins, datarange, format, suffix, path, rows, 
>> columns, num, last, fontmap, verbose)
>> 576 
>> 577 # Generate histogram
>> --> 578 hist(data.tolist(), bins, histtype='stepfilled')
>> 579 
>> 580 xlim(datarange)
>> 
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\pyplot.py
>>  in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, 
>> align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
>>2956   histtype=histtype, align=align, 
>> orientation=orientation,
>>2957   rwidth=rwidth, log=log, color=color, 
>> label=label,
>> -> 2958   stacked=stacked, data=data, **kwargs)
>>2959 finally:
>>2960 ax.hold(washold)
>> 
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\__init__.py
>>  in inner(ax, *args, **kwargs)
>>1809 warnings.warn(msg % (label_namer, func.__name__),
>>1810   RuntimeWarning, stacklevel=2)
>> -> 1811 return func(ax, *args, **kwargs)
>>1812 pre_doc = inner.__doc__
>>1813 if pre_doc is None:
>> 
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_axes.py
>>  in hist(self, x, bins, range, normed, weights, cumulative, bottom, 
>> histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
>>6192 ymin = np.amin(m[m != 0])
>>6193 # filter out the 0 height bins
>> -> 6194 ymin = max(ymin*0.9, minimum) if not input_empty 
>> else minimum
>>6195 ymin = min(ymin0, ymin)
>>6196 self.dataLim.intervaly = (ymin, ymax)
>> 
>> UnboundLocalError: local variable 'ymin' referenced before assignment 
>> /
>> 
>> I have no clue at all on debug it. Could you help me?
>> Thanks,
>
> Excuse me. The code link should be this one:
>
> http://nbviewer.ipython.org/gist/aflaxman/8329ec1b9f861469f896
>
> Do you experience such errors?


>From a quick look, it appears that you are trying to plot a histogram
in which all the bins are empty.


-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Library function to encode data to multipart/form-data format?

2015-12-21 Thread Grant Edwards
Is there a standard library function that can be used to encode data
into multipart/form-data format?  IIRC, I looked for this once before
and didn't find anything in the library. 

[I don't want to actually send an HTTP POST or an email message, I
just need to generate sets of data for test purposes.]

-- 
Grant Edwards   grant.b.edwardsYow! -- I love KATRINKA
  at   because she drives a
  gmail.comPONTIAC.  We're going
   away now.  I fed the cat.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What could cause a plot fail in my code?

2015-12-21 Thread Peter Otten
Robert wrote:

> Hi,
> 
> I find a useful code snippet on link:
> 
> http://stackoverflow.com/questions/25126444/logistic-regression-in-pymc/34400966#34400966
> 
> but it has error on plot function. The error message is as following:
> -
> %run "C:\Users\rj\pyprj\logic_regression0.py"
> [-100%-] 1 of 1 complete in 12.6  
> [secPlotting beta0
> Plotting tau
> Plotting betaSalad
> Plotting sigma
> 
---
> UnboundLocalError Traceback (most recent call
> last) C:\Users\pyprj\logic_regression0.py in ()
>  34 #m.sample(10, 5, 50)
>  35 m.sample(1, 5000, 50)
> ---> 36 pm.Matplot.plot(m)
>  37 import matplotlib.pyplot as plt
>  38 #plt.plot(m)
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-
> packages\pymc\Matplot.pyc in wrapper(pymc_obj, *args, **kwargs)
> 339 if args:
> 340 name = '%s_%s' % (args[0],
> variable.__name__)
> --> 341 f(data, name, *args, **kwargs)
> 342 return
> 343 except AttributeError:
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-
packages\pymc\Matplot.pyc
> in plot(data, name, format, suffix, path,  common_scale, datarange, new,
> last, rows, num, fontmap, verbose)
> 453 num=num * 2,
> 454 last=last,
> --> 455 fontmap=fontmap)
> 456
> 457 if last:
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-
packages\pymc\Matplot.pyc
> in wrapper(pymc_obj, *args, **kwargs)
> 375
> 376 # If others fail, assume that raw data is passed
> --> 377 f(pymc_obj, *args, **kwargs)
> 378
> 379 wrapper.__doc__ = f.__doc__
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-
packages\pymc\Matplot.pyc
> in histogram(data, name, bins, datarange, format, suffix, path, rows,
> columns, num, last, fontmap, verbose)
> 576
> 577 # Generate histogram
> --> 578 hist(data.tolist(), bins, histtype='stepfilled')
> 579
> 580 xlim(datarange)
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-
packages\matplotlib\pyplot.py
> in hist(x, bins, range, normed, weights, cumulative, bottom, histtype,
> align, orientation, rwidth, log, color, label, stacked, hold, data,
> **kwargs)
>2956   histtype=histtype, align=align,
>orientation=orientation,
>2957   rwidth=rwidth, log=log, color=color,
>label=label,
> -> 2958   stacked=stacked, data=data, **kwargs)
>2959 finally:
>2960 ax.hold(washold)
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-
packages\matplotlib\__init__.py
> in inner(ax, *args, **kwargs)
>1809 warnings.warn(msg % (label_namer,
>func.__name__),
>1810   RuntimeWarning, stacklevel=2)
> -> 1811 return func(ax, *args, **kwargs)
>1812 pre_doc = inner.__doc__
>1813 if pre_doc is None:
> 
> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-
packages\matplotlib\axes\_axes.py
> in hist(self, x, bins, range, normed, weights, cumulative, bottom,
> histtype, align, orientation, rwidth, log, color, label, stacked,
> **kwargs)
>6192 ymin = np.amin(m[m != 0])
>6193 # filter out the 0 height bins
> -> 6194 ymin = max(ymin*0.9, minimum) if not input_empty
> else minimum
>6195 ymin = min(ymin0, ymin)
>6196 self.dataLim.intervaly = (ymin, ymax)
> 
> UnboundLocalError: local variable 'ymin' referenced before assignment
> /
> 
> I have no clue at all on debug it. Could you help me?

To me that looks like a bug in matplotlib. ymin is not properly initialised 
before the loop

"""
for m in n:
if np.sum(m) > 0:  # make sure there are counts
ymin = np.amin(m[m != 0])
# filter out the 0 height bins
ymin = max(ymin*0.9, minimum) if not input_empty else 
minimum
"""

so if for there aren't any m with np.sum(m) > 0 (i. e. all bins are empty) 
you get the error. Here's a made-up example for illustration:

>>> def last_positive_item(items):
... for item in items:
... if item > 0:
... last = item
... return last
... 

As long as you pass at least one positive item everything seems OK:

>>> last_positive_item([1, 2, -3, 3])
3

But if you don't you get the error:

>>> last_positive_item([-1, -2, -3, 0])
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 5, in last_positive_item
UnboundLocalError: local variable 'last' referenced before assignment

Please file a bug report if there isn't one already.

-- 
https://mai

Re: IDLE 3.5.1 quits unexpectedly (portuguese keyboard)

2015-12-21 Thread eryk sun
On Fri, Dec 18, 2015 at 9:15 PM, Osvaldo Dias dos Santos
 wrote:
>
> Pressing the tilde key my iMac portuguese keyboard quits IDLE
> unexpectedly (along with any associated files I may be working
> on, including code).
>
> The keyboard image is attached. The tilde key is the second
> orange one from the top.

There's no file attached. Attachments are unreliable on a list. This
should suffice:

https://en.wikipedia.org/wiki/Portuguese_keyboard_layout

> This key is very important in this language, because pressing
> it together with the shift key, the caret ( ^ ) symbol is
> entered. So, if I try to enter a caret and press the shift and
> the tilde key to do it, IDLE quits and any unsaved file
> information (even code) is lost. Then Apple crash report window
> opens, but if I click the reopen button nothing happens, IDLE
> does not reopen.

I know on Linux, Tk 8.6 has a problem with dead keys when using an
international keyboard layout (see issue 25356 [1]). This crash could
be related to whatever causes the problem on Linux. Try running a
simple test.tcl script via wish:

text .t
pack .t

Does wish crash when you press tilde in the window?

[1]: http://bugs.python.org/issue25356
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:

2015-12-21 Thread eryk sun
On Mon, Dec 21, 2015 at 3:08 AM, Animesh Srivastava  wrote:
> While installin python3.5.1 i m getting 0xc07b error

0xC07B is STATUS_INVALID_IMAGE_FORMAT, so there's something wrong
with the executable. Try clearing your browser cache and download the
installer again.
-- 
https://mail.python.org/mailman/listinfo/python-list


How can I produce ARFF files using word2vec-toolkit

2015-12-21 Thread saurabhtiwaririshi
I am doing a machine learning project and I need ARFF files to feed my data to 
Weka. 
How can I use word2-vec to produce ARFF files.
An example would be much helpful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-21 Thread Grant Edwards
On 2015-12-21, Dennis Lee Bieber  wrote:
> On Mon, 21 Dec 2015 13:40:21 +0100, "Skybuck Flying"
> declaimed the following:
>
>>The original idea I posted is less about sending a signal to another 
>>processor.
>>
>>It is more about how to break out of an instruction sequence.
>>
>>Example of problem:
>>
>>Main:
>>while Condition1 do
>>begin
>>while Condition2 do
>>begin
>>while Condition3 do
>>begin
>>Routine1
>>end
>>end;
>>end;
>>
>   I do hope this is the result of over simplification for the example, as
> otherwise I'd turn it into
>
> while C1 and  C2 and C3:
>   R1

That's not equivalent to what Skybuck posted.  Think about what
happens when Routine1 causes Condition1 and Condition2 to become false
but Condition3 remains true.

Not that this means that all rest of what Skyhawk posted makes any
sense at all.  I've spent a lot of time programming on "bare metal",
in assembly, Pascal, PL/M, and C (including using coroutines and
various other "multi-thread" constructs with no OS support), and I
really don't see the utility of his initial suggestion.

-- 
Grant Edwards   grant.b.edwardsYow! What a COINCIDENCE!
  at   I'm an authorized "SNOOTS
  gmail.comOF THE STARS" dealer!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ignore error with non-zero exit status

2015-12-21 Thread Ian Kelly
On Sun, Dec 20, 2015 at 3:46 PM, Thomas 'PointedEars' Lahn
 wrote:
> Chris Angelico wrote:
>
>> On Mon, Dec 21, 2015 at 8:22 AM, Thomas 'PointedEars' Lahn
>>  wrote:
>
> It is supposed to be an attribution *line*, _not_ an attribution novel.
> Also, the “(was: …)” part is to be removed from the Subject header field
> value to complete the change of subject in a thread.

Better yet, please don't change the Subject header for trivial reasons
in the first place. This isn't just a Usenet group; it's also a
mailing list, and many MUAs rely on the Subject header for proper
threading.
-- 
https://mail.python.org/mailman/listinfo/python-list


Meaning and purpose of the Subject field (was: Ignore error with non-zero exit status)

2015-12-21 Thread Ben Finney
Ian Kelly  writes:

> Better yet, please don't change the Subject header for trivial reasons
> in the first place.

When the subject of the ongoing discussion changes, it's normal to
change the Subject field accordingly.

I agree with your admonition against trivial alterations to that field;
I hope you agree with me that it is not trivial, but rather is normal
and helpful, to update the Subject field to track significant changes in
the subject of the discussion.

> This isn't just a Usenet group; it's also a mailing list, and many
> MUAs rely on the Subject header for proper threading.

If such MUAs do that, they're misinterpreting the Subject field. Other
fields are available with the explicit meaning of relating messages to
each other regardless of what they discuss.

If the correct fields are being mangled, then the correct place to apply
pressure is on those who can fix that error. Let's not overload the
Subject field to make up the lack.

-- 
 \   “Self-respect: The secure feeling that no one, as yet, is |
  `\suspicious.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: Meaning and purpose of the Subject field (was: Ignore error with non-zero exit status)

2015-12-21 Thread Ian Kelly
On Mon, Dec 21, 2015 at 1:58 PM, Ben Finney  wrote:
> Ian Kelly  writes:
>> This isn't just a Usenet group; it's also a mailing list, and many
>> MUAs rely on the Subject header for proper threading.
>
> If such MUAs do that, they're misinterpreting the Subject field. Other
> fields are available with the explicit meaning of relating messages to
> each other regardless of what they discuss.
>
> If the correct fields are being mangled, then the correct place to apply
> pressure is on those who can fix that error. Let's not overload the
> Subject field to make up the lack.

It might just be Gmail.

http://webapps.stackexchange.com/questions/965/how-does-gmail-decide-to-thread-email-messages

I can't specifically recall if I've used any MUA other than Gmail that
even attempts threading email messages.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Meaning and purpose of the Subject field (was: Ignore error with non-zero exit status)

2015-12-21 Thread Jon Ribbens
On 2015-12-21, Ian Kelly  wrote:
> On Mon, Dec 21, 2015 at 1:58 PM, Ben Finney  
> wrote:
>> Ian Kelly  writes:
>>> This isn't just a Usenet group; it's also a mailing list, and many
>>> MUAs rely on the Subject header for proper threading.
>>
>> If such MUAs do that, they're misinterpreting the Subject field. Other
>> fields are available with the explicit meaning of relating messages to
>> each other regardless of what they discuss.
>>
>> If the correct fields are being mangled, then the correct place to apply
>> pressure is on those who can fix that error. Let's not overload the
>> Subject field to make up the lack.
>
> It might just be Gmail.
>
> http://webapps.stackexchange.com/questions/965/how-does-gmail-decide-to-thread-email-messages
>
> I can't specifically recall if I've used any MUA other than Gmail that
> even attempts threading email messages.

Also: Thunderbird, The Bat!, Eudora, Gnus, Outlook, Outlook Express,
Pegasus Mail, Pine, Apple Mail, Windows Live Mail, Yahoo Mail,
Evolution, SquirrelMail, KMail, Windows Mail, etc.

Trying to suggest that MUAs should never look at the Subject line for
threading is, unfortunately, ridiculous. Yes, in theory it shouldn't
be necessary but in practice enough people are using poor clients that
don't provide enough context in the proper headers that it can't be
avoided.

And, yes, fixing the mail clients of "everybody else in the world"
might be a lovely idea but it is a little impractical to implement.
-- 
https://mail.python.org/mailman/listinfo/python-list


In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?

2015-12-21 Thread Aaron
Hello,

I am trying to figure out how to populate a shelve file with a nested 
dictionary.

These are my requirements:

-Create shelve file called people.db
-Append the shelve file with new people (person_1, person_2, etc.).
-Use a for loop to iterate through 'attributes' so that I do not need to write 
out the lengthy code line by line to populate to the shelve file.
-Need to reference shelve file data for future use

Here is the key/value format that I would like to append to the shelve file.

person_1 = { 'name': 'Bob', 'type': 'employee', 'attributes':
[{'game': 'basketball', 'high score': '100', 'time': '3.34'},
{'game': 'bridge', 'high score': '10', 'time': '30.34'},
{'game': 'foosball', 'high score': '2', 'time': '24'}]
'''
50+ other attributes
'''
}

# Example: s['person_1]['attributes'][2]['time'] would call out '24'.
# 's' is from 's = shelve.open('people')'
I have a dictionary dictPeople.py file (created using pprint() that contains 
the information of person_1, etc. And I am extracting only a small percentage 
of the data that is needed.

I have tried the following, but I get an invalid key error.

import shelve, dictPeople
s = shelve.open('people')
person = 'person_1'
s[person]['name'] = dictPeople.person_1['name']
s[person]['type'] = dictPeople.person_1['type']
# I need to use this for loop because there are 50+ attributes.
for attribute in range(0, len(dictPeople['attributes'][attribute])):
s[person]['attributes'][attribute]['game'] = \
dictPeople['attributes'][attribute]['game']
s[person]['attributes'][attribute]['high score'] = \
dictPeople['attributes'][attribute]['high score']
s[person]['attributes'][attribute]['time'] = \
dictPeople['attributes'][attribute]['time']
It turns out, I get the key error because I am not allowed to reference a 
key/value pair the same way that I can with a dictionary. However, the crazy 
thing is that I can call values in the db file using the same exact format when 
trying to write.

For example: I can read data from the .db file using:

x = s['person_1']['name']
print(x)
BUT! I cannot write to that .db file using that exact format or I get an 
invalid key error. Makes no sense!

s['person_1']['name'] = 'Bob'
# Returns invalid key entry.  Makes no sense.
Therefore, I tried to extract data and populate the db file using the following:

s[person] = {   'name': dictPeople.person_1['name'],
'type': dictPeople.person_1['type'],
for attribute in range(0, len(dictPeople['attributes'][attribute])):
['game':  dictPeople['attributes'][attribute]['game'],
'high score': dictPeople['attributes'][attribute]['high score'],
'time': dictPeople['attributes'][attribute]['time']]

}
But, this obvously doesn't work because of the for loop. How can I do this?

-I am trying to figure out how to extract data from the dictionary 
dictPeople.py file and store it in the people.db file.
-I am trying to add new people to the people.db file as more people become 
available.
-I need to use the for loop because of the 50+ attributes I need to add.
-My future steps would be to modify some of the data values that I extract and 
used to populate the people.db file, but my first step is to, at least, 
extract, and then populate the people.db file.

Any help or guidance is greatly appreciated.  Thank you for your time and 
reading my question.

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


In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?

2015-12-21 Thread Aaron Christensen
Hello,

I am trying to figure out how to populate a shelve file with a nested
dictionary.

These are my requirements:

-Create shelve file called people.db
-Append the shelve file with new people (person_1, person_2, etc.).
-Use a for loop to iterate through 'attributes' so that I do not need to
write out the lengthy code line by line to populate to the shelve file.
-Need to reference shelve file data for future use

Here is the key/value format that I would like to append to the shelve
file.

person_1 = { 'name': 'Bob', 'type': 'employee', 'attributes':
[{'game': 'basketball', 'high score': '100', 'time': '3.34'},
{'game': 'bridge', 'high score': '10', 'time': '30.34'},
{'game': 'foosball', 'high score': '2', 'time': '24'}]
'''
50+ other attributes
'''
}

# Example: s['person_1]['attributes'][2]['time'] would call out '24'.
# 's' is from 's = shelve.open('people')'
I have a dictionary dictPeople.py file (created using pprint() that
contains the information of person_1, etc. And I am extracting only a small
percentage of the data that is needed.

I have tried the following, but I get an invalid key error.

import shelve, dictPeople
s = shelve.open('people')
person = 'person_1'
s[person]['name'] = dictPeople.person_1['name']
s[person]['type'] = dictPeople.person_1['type']
# I need to use this for loop because there are 50+ attributes.
for attribute in range(0, len(dictPeople['attributes'][attribute])):
s[person]['attributes'][attribute]['game'] = \
dictPeople['attributes'][attribute]['game']
s[person]['attributes'][attribute]['high score'] = \
dictPeople['attributes'][attribute]['high score']
s[person]['attributes'][attribute]['time'] = \
dictPeople['attributes'][attribute]['time']
It turns out, I get the key error because I am not allowed to reference a
key/value pair the same way that I can with a dictionary. However, the
crazy thing is that I can call values in the db file using the same exact
format when trying to write.

For example: I can read data from the .db file using:

x = s['person_1']['name']
print(x)
BUT! I cannot write to that .db file using that exact format or I get an
invalid key error. Makes no sense!

s['person_1']['name'] = 'Bob'
# Returns invalid key entry.  Makes no sense.
Therefore, I tried to extract data and populate the db file using the
following:

s[person] = {   'name': dictPeople.person_1['name'],
'type': dictPeople.person_1['type'],
for attribute in range(0, len(dictPeople['attributes'][attribute])):
['game':  dictPeople['attributes'][attribute]['game'],
'high score': dictPeople['attributes'][attribute]['high score'],
'time': dictPeople['attributes'][attribute]['time']]

}
But, this obvously doesn't work because of the for loop. How can I do this?

-I am trying to figure out how to extract data from the dictionary
dictPeople.py file and store it in the people.db file.
-I am trying to add new people to the people.db file as more people become
available.
-I need to use the for loop because of the 50+ attributes I need to add.
-My future steps would be to modify some of the data values that I extract
and used to populate the people.db file, but my first step is to, at least,
extract, and then populate the people.db file.

Any help or guidance is greatly appreciated.  Thank you for your time and
reading my question.

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


Re: Meaning and purpose of the Subject field

2015-12-21 Thread Thomas 'PointedEars' Lahn
Jon Ribbens wrote:

> On 2015-12-21, Ian Kelly  wrote:
>> I can't specifically recall if I've used any MUA other than Gmail that
>> even attempts threading email messages.
> 
> Also: Thunderbird, The Bat!, Eudora, Gnus, Outlook, Outlook Express,
> Pegasus Mail, Pine, Apple Mail, Windows Live Mail, Yahoo Mail,
> Evolution, SquirrelMail, KMail, Windows Mail, etc.

Yes, of course.
 
> Trying to suggest that MUAs should never look at the Subject line for
> threading is, unfortunately, ridiculous.

No, it is what the Internet message standard says instead:

,-
| 
| 3.6.4.  Identification Fields
| 
| Though listed as optional in the table in section 3.6, every message
| SHOULD have a "Message-ID:" field.  Furthermore, reply messages
| SHOULD have "In-Reply-To:" and "References:" fields as appropriate
| and as described below.
| 
| The "Message-ID:" field contains a single unique message identifier.
| The "References:" and "In-Reply-To:" fields each contain one or more
| unique message identifiers, optionally separated by CFWS.

(“SHOULD” in an RFC means: “do as I say unless you can give me a very good 
reason not to do it”.  See RFC 2119 for details.)

vs.

,-
| 
| 3.6.5.  Informational Fields
| 
| The informational fields are all optional.  The "Subject:" and
| "Comments:" fields are unstructured fields as defined in section
| 2.2.1, and therefore may contain text or folding white space. […]

> Yes, in theory it shouldn't be necessary

It is not.

> but in practice enough people are using poor clients that don't provide
> enough context in the proper headers that it can't be avoided.

That Internet communication is made more difficult for *all* because a 
*perceived* majority of *perceived* clients is broken, is putting upside 
down the good Internet principle of “be conservative in what to send, 
liberal in what to receive”.

Those b0rked clients should either be fixed at once or not be used, period.

Instead, in practice, the Python mailing list software is b0rked since I 
know of the mailing list’s/newsgroups’ existence (several years ago): it is 
b0rked in the regard that its distributor does not consider that it is also 
posted to a Usenet newsgroup where articles require a References header 
field to be properly threaded.  Incidentally, that References header field 
is, in the absence of an In-Reply-To header field, used by hybrid e 
mail/NetNews agents such as Thunderbird, in full compliance with the NetNews 
message standard:

,-
| 
| 3.  News Header Fields
| 
|The following news header fields extend those defined in Section 3.6
|of [RFC5322]:
| 
| […]
| 3.2.10.  References
| 
|The References header field is the same as that specified in Section
|3.6.4 of [RFC5322], with the added restrictions detailed above in
|Section 2.2 and those listed below: […]

One could kill two birds with one stone here by fixing this, but it is not 
done.  Why?

> And, yes, fixing the mail clients of "everybody else in the world"
> might be a lovely idea but it is a little impractical to implement.

I find your argument strewn with gaping defects in logic.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Meaning and purpose of the Subject field (was: Ignore error with non-zero exit status)

2015-12-21 Thread Steven D'Aprano
On Tue, 22 Dec 2015 08:44 am, Jon Ribbens wrote about mail clients that use
the Subject line to thread messages:

> Also: Thunderbird, The Bat!, Eudora, Gnus, Outlook, Outlook Express,
> Pegasus Mail, Pine, Apple Mail, Windows Live Mail, Yahoo Mail,
> Evolution, SquirrelMail, KMail, Windows Mail, etc.

I understand that at least some of those will only use the Subject as a
fallback when other threading information is not available. That's a
reasonable strategy to take.

As for mail clients that *always* and *exclusively* use the subject line to
implement threading, they are horrifically broken. It is completely
unreasonable to insist that people using non-broken tools must change their
habits to support those with completely broken tools.

So as far as I am concerned, if changes of subject line breaks threading for
you, so sad, too bad. Go without threading or use a better mail client.


> Trying to suggest that MUAs should never look at the Subject line for
> threading is, unfortunately, ridiculous. Yes, in theory it shouldn't
> be necessary but in practice enough people are using poor clients that
> don't provide enough context in the proper headers that it can't be
> avoided.

*shrug*

The whole purpose of the change of subject is to indicate in a human-visible
way that the subject of the thread has changed, i.e. that it is a new
thread derived from the old one. If that breaks threading, oh well, it
breaks threading.


> And, yes, fixing the mail clients of "everybody else in the world"
> might be a lovely idea but it is a little impractical to implement.

Less impractical than insisting that "everybody else in the world" must
change their posting habits to suit those using broken mail clients.

The fact is, even if nobody ever changed the subject line, sometimes
threading will be broken. I can't find the energy to care about something
which already only sometimes works.




-- 
Steven

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


Re: Meaning and purpose of the Subject field (was: Ignore error with non-zero exit status)

2015-12-21 Thread Jon Ribbens
On 2015-12-21, Steven D'Aprano  wrote:
> On Tue, 22 Dec 2015 08:44 am, Jon Ribbens wrote about mail clients that use
> the Subject line to thread messages:
>> Also: Thunderbird, The Bat!, Eudora, Gnus, Outlook, Outlook Express,
>> Pegasus Mail, Pine, Apple Mail, Windows Live Mail, Yahoo Mail,
>> Evolution, SquirrelMail, KMail, Windows Mail, etc.
>
> I understand that at least some of those will only use the Subject as a
> fallback when other threading information is not available. That's a
> reasonable strategy to take.
>
> As for mail clients that *always* and *exclusively* use the subject
> line to implement threading, they are horrifically broken.

Yes, that would be bizarre and clearly wrong. Are there any such clients?
I wouldn't put it past Microsoft to do such a thing, of course ;-)

> So as far as I am concerned, if changes of subject line breaks
> threading for you, so sad, too bad. Go without threading or use a
> better mail client.

I have no comment on that.

> The whole purpose of the change of subject is to indicate in a human-visible
> way that the subject of the thread has changed, i.e. that it is a new
> thread derived from the old one. If that breaks threading, oh well, it
> breaks threading.

That sounds a bit confused - if the *intention* of changing the
subject line is to create a new thread, then breaking the thread
is not "breaking threading" ;-)

>> And, yes, fixing the mail clients of "everybody else in the world"
>> might be a lovely idea but it is a little impractical to implement.
>
> Less impractical than insisting that "everybody else in the world" must
> change their posting habits to suit those using broken mail clients.

Fortunately I haven't suggested that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ignore error with non-zero exit status

2015-12-21 Thread Steven D'Aprano
On Tue, 22 Dec 2015 09:27 am, Thomas 'PointedEars' Lahn wrote:

[...]
> No, it is not.  Your logic is flawed, too, pseudonymous nobody with the
> unreadable posting style.

If its unreadable, how do you know what it says?

"PointedEars", you're doing a marvellous job of acting like a self-righteous
and hypocritical buffoon who constantly complains about the most trivial
matters when committed by others, while ignoring that you do the same sort
of things.

You whinge about others using "fake names", whatever that means, when you
yourself go by a fake name "PointedEars".

You whinge about people's attribution lines extending over two virtual
lines, as if that matters, while ignoring the fact that your sig is twice
as long as is polite.

You whinge about people posting "dumb questions", while continuing to post
dumb answers.

When you make an error of logic, your response is never to accept that you
were wrong, but you just compound the error by insisting that the other
party is the one with flawed logic.

So, Thomas, if that is your real name, get over yourself. I don't know what
small pond you have come from, but you're in the big ocean of the Internet
now, and you're no longer the smartest person around. Admit it when you
make a mistake, and stop being such so whiny, prissy and unhelpful.

Or, if you can't do that, just go away and whine on some other newsgroup
where they might be impressed by your astonishing lack of social know-how.

Thank you.


-- 
Steven

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


Re: Library function to encode data to multipart/form-data format?

2015-12-21 Thread Laura Creighton
In a message of Mon, 21 Dec 2015 17:51:00 +, Grant Edwards writes:
>Is there a standard library function that can be used to encode data
>into multipart/form-data format?  IIRC, I looked for this once before
>and didn't find anything in the library. 
>
>[I don't want to actually send an HTTP POST or an email message, I
>just need to generate sets of data for test purposes.]
>
>-- 
>Grant Edwards   grant.b.edwardsYow! -- I love KATRINKA
>  at   because she drives a
>  gmail.comPONTIAC.  We're going
>   away now.  I fed the cat.
>-- 
>https://mail.python.org/mailman/listinfo/python-list

Cannibalise this:
http://code.activestate.com/recipes/146306/
which just uses standard library things.

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


Re: Ignore error with non-zero exit status

2015-12-21 Thread Terry Reedy

On 12/21/2015 9:05 AM, Thomas 'PointedEars' Lahn wrote:

Chris Angelico wrote:


On Tue, Dec 22, 2015 at 12:19 AM, Thomas 'PointedEars' Lahn
 wrote:

Mark Lawrence wrote:

On 21/12/2015 07:51, Thomas 'PointedEars' Lahn wrote:

Chris Angelico wrote:

But it's been clearly stated that .format is not going to do away with
percent formatting, and all language of "new-style formatting" has
been removed so as not to cause confusion.

Wishful thinking, twice.

http://www.gossamer-threads.com/lists/python/dev/969817

What is this supposed to be evidence of?


Proof that percent formatting isn't planned for deprecation, much less
removal.


Then it would have failed to accomplish that.


There is strong support for it in certain quarters of python-dev. […]


There *was*.  The referred thread is from 2012-02.  It is 2015-12.


Nothing has changed since except for
https://www.python.org/dev/peps/pep-0498/
already added to 3.6.

If the 2.7 doc still implies that % -formatting is deprecated, it should 
changed as in the 3.x docs.


--
Terry Jan Reedy


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


Re: Meaning and purpose of the Subject field (was: Ignore error with non-zero exit status)

2015-12-21 Thread Ian Kelly
On Mon, Dec 21, 2015 at 4:24 PM, Jon Ribbens
 wrote:
> On 2015-12-21, Steven D'Aprano  wrote:
>> The whole purpose of the change of subject is to indicate in a human-visible
>> way that the subject of the thread has changed, i.e. that it is a new
>> thread derived from the old one. If that breaks threading, oh well, it
>> breaks threading.
>
> That sounds a bit confused - if the *intention* of changing the
> subject line is to create a new thread, then breaking the thread
> is not "breaking threading" ;-)
>
>>> And, yes, fixing the mail clients of "everybody else in the world"
>>> might be a lovely idea but it is a little impractical to implement.
>>
>> Less impractical than insisting that "everybody else in the world" must
>> change their posting habits to suit those using broken mail clients.
>
> Fortunately I haven't suggested that.

Yes, I only requested that people not change the subject headers for
trivial reasons, by which I meant things like fixing typos (as in the
subject header change that brought about this thread). I also only
intended my request in the context of this forum, which is shared
between Usenet and mailing list users. Changing the subject header to
indicate a change in subject is, of course, fine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ignore error with non-zero exit status

2015-12-21 Thread Chris Angelico
On Tue, Dec 22, 2015 at 10:53 AM, Terry Reedy  wrote:
> Nothing has changed since except for
> https://www.python.org/dev/peps/pep-0498/
> already added to 3.6.

And the flip side of the argument is
https://www.python.org/dev/peps/pep-0461/ in 3.5, expanding on percent
formatting. Both are useful, both are supported.

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


Re: Ignore error with non-zero exit status

2015-12-21 Thread Ian Kelly
On Dec 21, 2015 4:55 PM, "Terry Reedy"  wrote:
>
> Nothing has changed since except for
> https://www.python.org/dev/peps/pep-0498/
> already added to 3.6.

https://xkcd.com/927/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?

2015-12-21 Thread Peter Otten
Aaron Christensen wrote:

> Hello,
> 
> I am trying to figure out how to populate a shelve file with a nested
> dictionary.
> 
> These are my requirements:
> 
> -Create shelve file called people.db
> -Append the shelve file with new people (person_1, person_2, etc.).
> -Use a for loop to iterate through 'attributes' so that I do not need to
> write out the lengthy code line by line to populate to the shelve file.
> -Need to reference shelve file data for future use
> 
> Here is the key/value format that I would like to append to the shelve
> file.
> 
> person_1 = { 'name': 'Bob', 'type': 'employee', 'attributes':
> [{'game': 'basketball', 'high score': '100', 'time': '3.34'},
> {'game': 'bridge', 'high score': '10', 'time': '30.34'},
> {'game': 'foosball', 'high score': '2', 'time': '24'}]
> '''
> 50+ other attributes
> '''
> }
> 
> # Example: s['person_1]['attributes'][2]['time'] would call out '24'.
> # 's' is from 's = shelve.open('people')'
> I have a dictionary dictPeople.py file (created using pprint() that
> contains the information of person_1, etc. And I am extracting only a
> small percentage of the data that is needed.
> 
> I have tried the following, but I get an invalid key error.
> 
> import shelve, dictPeople
> s = shelve.open('people')
> person = 'person_1'
> s[person]['name'] = dictPeople.person_1['name']
> s[person]['type'] = dictPeople.person_1['type']
> # I need to use this for loop because there are 50+ attributes.
> for attribute in range(0, len(dictPeople['attributes'][attribute])):
> s[person]['attributes'][attribute]['game'] = \
> dictPeople['attributes'][attribute]['game']
> s[person]['attributes'][attribute]['high score'] = \
> dictPeople['attributes'][attribute]['high score']
> s[person]['attributes'][attribute]['time'] = \
> dictPeople['attributes'][attribute]['time']
> It turns out, I get the key error because I am not allowed to reference a
> key/value pair the same way that I can with a dictionary. However, the
> crazy thing is that I can call values in the db file using the same exact
> format when trying to write.
> 
> For example: I can read data from the .db file using:
> 
> x = s['person_1']['name']
> print(x)
> BUT! I cannot write to that .db file using that exact format or I get an
> invalid key error. Makes no sense!
> 
> s['person_1']['name'] = 'Bob'
> # Returns invalid key entry.  Makes no sense.
> Therefore, I tried to extract data and populate the db file using the
> following:
> 
> s[person] = {   'name': dictPeople.person_1['name'],
> 'type': dictPeople.person_1['type'],
> for attribute in range(0, len(dictPeople['attributes'][attribute])):
> ['game':  dictPeople['attributes'][attribute]['game'],
> 'high score': dictPeople['attributes'][attribute]['high score'],
> 'time': dictPeople['attributes'][attribute]['time']]
> 
> }
> But, this obvously doesn't work because of the for loop. How can I do
> this?
> 
> -I am trying to figure out how to extract data from the dictionary
> dictPeople.py file and store it in the people.db file.
> -I am trying to add new people to the people.db file as more people become
> available.
> -I need to use the for loop because of the 50+ attributes I need to add.
> -My future steps would be to modify some of the data values that I extract
> and used to populate the people.db file, but my first step is to, at
> least, extract, and then populate the people.db file.
> 
> Any help or guidance is greatly appreciated.  Thank you for your time and
> reading my question.

You don't need these loops. The problem is that when you read the dict from 
the db

db = shelve.open(...)
person = db["person_1"]

person is a Python object completely independent of the shelve and the 
shelve has no way to trace changes to that object:

$ python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shelve
>>> db = shelve.open("tmp.shelve")
>>> person_1 = { 'name': 'Bob', 'type': 'employee', 'attributes':
... [{'game': 'basketball', 'high score': '100', 'time': '3.34'},
... {'game': 'bridge', 'high score': '10', 'time': '30.34'},
... {'game': 'foosball', 'high score': '2', 'time': '24'}]
... }
>>> db["person_1"] = person_1
>>> db["person_1"]["age"] = 42
>>> db.close()
>>> db = shelve.open("tmp.shelve")
>>> db["person_1"]
{'name': 'Bob', 'type': 'employee', 'attributes': [{'time': '3.34', 'high 
score': '100', 'game': 'basketball'}, {'time': '30.34', 'high score': '10', 
'game': 'bridge'}, {'time': '24', 'high score': '2', 'game': 'foosball'}]}

When you look at the data you see that there is no "age" key. The straight-
forward fix is to always use an assignment 

db[key] = new_value

when you want a change:

>>> person = db["person_1"]
>>> person["age"] = 42
>>> db["person_1"] = person
>>> db.close()

That way the change will survive:

>>> db = she

Re: Ignore error with non-zero exit status

2015-12-21 Thread Chris Angelico
On Tue, Dec 22, 2015 at 11:17 AM, Ian Kelly  wrote:
> On Dec 21, 2015 4:55 PM, "Terry Reedy"  wrote:
>>
>> Nothing has changed since except for
>> https://www.python.org/dev/peps/pep-0498/
>> already added to 3.6.
>
> https://xkcd.com/927/

The 927ness of it was discussed at length prior to implementation. PEP
498 isn't really another competing string format operation; it's more
like an alternative expression format. It's more in competition with
this:

msg = "The sum of " + str(x) + " and " + str(y) + " is " + str(x+y) + "."

which puts the interpolated expressions at the "correct place" in the
string - but at the cost of being verbose, messy, and error-prone.
Compare:

msg = f"The sum of {x} and {y} is {x+y}."

(Yes, there's a slight semantic difference; the latter uses format()
rather than str(). But otherwise, it's compiled to the "".join(...)
equivalent of the repeated concatenation example.)

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


Re: Catogorising strings into random versus non-random

2015-12-21 Thread Rick Johnson
On Sunday, December 20, 2015 at 10:22:57 PM UTC-6, Chris Angelico wrote:
> DuckDuckGo doesn't give a result count, so I skipped it. Yahoo search yielded:

So why bother to mention it then? Is this another one of your "pikeish" 
propaganda campaigns?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Meaning and purpose of the Subject field (was: Ignore error with non-zero exit status)

2015-12-21 Thread Cameron Simpson

On 22Dec2015 10:14, Steven D'Aprano  wrote:

On Tue, 22 Dec 2015 08:44 am, Jon Ribbens wrote about mail clients that use
the Subject line to thread messages:


Also: Thunderbird, The Bat!, Eudora, Gnus, Outlook, Outlook Express,
Pegasus Mail, Pine, Apple Mail, Windows Live Mail, Yahoo Mail,
Evolution, SquirrelMail, KMail, Windows Mail, etc.


I understand that at least some of those will only use the Subject as a
fallback when other threading information is not available. That's a
reasonable strategy to take.

As for mail clients that *always* and *exclusively* use the subject line to
implement threading, they are horrifically broken.


A big +1 here. Even as big as +2.


It is completely
unreasonable to insist that people using non-broken tools must change their
habits to support those with completely broken tools.

So as far as I am concerned, if changes of subject line breaks threading for
you, so sad, too bad. Go without threading or use a better mail client.

[...snip...]

Besides, changing the Subject line is _supposed_ to break the threading in 
these contexts: such clients clearly consider the discussion topic (subject) as 
sufficient definition of a thread, and changing the topic should imply a new 
thread to such simplistic clients.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?

2015-12-21 Thread Aaron Christensen
Hi Peter,

Thanks for the response!  Several things you stated definitely got me
thinking.  I really appreciate the response.  I used what you said and I am
able to accomplish what I needed.

Thanks!
Aaron



On Mon, Dec 21, 2015 at 7:23 PM, Peter Otten <__pete...@web.de> wrote:

> Aaron Christensen wrote:
>
> > Hello,
> >
> > I am trying to figure out how to populate a shelve file with a nested
> > dictionary.
> >
> > These are my requirements:
> >
> > -Create shelve file called people.db
> > -Append the shelve file with new people (person_1, person_2, etc.).
> > -Use a for loop to iterate through 'attributes' so that I do not need to
> > write out the lengthy code line by line to populate to the shelve file.
> > -Need to reference shelve file data for future use
> >
> > Here is the key/value format that I would like to append to the shelve
> > file.
> >
> > person_1 = { 'name': 'Bob', 'type': 'employee', 'attributes':
> > [{'game': 'basketball', 'high score': '100', 'time': '3.34'},
> > {'game': 'bridge', 'high score': '10', 'time': '30.34'},
> > {'game': 'foosball', 'high score': '2', 'time': '24'}]
> > '''
> > 50+ other attributes
> > '''
> > }
> >
> > # Example: s['person_1]['attributes'][2]['time'] would call out '24'.
> > # 's' is from 's = shelve.open('people')'
> > I have a dictionary dictPeople.py file (created using pprint() that
> > contains the information of person_1, etc. And I am extracting only a
> > small percentage of the data that is needed.
> >
> > I have tried the following, but I get an invalid key error.
> >
> > import shelve, dictPeople
> > s = shelve.open('people')
> > person = 'person_1'
> > s[person]['name'] = dictPeople.person_1['name']
> > s[person]['type'] = dictPeople.person_1['type']
> > # I need to use this for loop because there are 50+ attributes.
> > for attribute in range(0, len(dictPeople['attributes'][attribute])):
> > s[person]['attributes'][attribute]['game'] = \
> > dictPeople['attributes'][attribute]['game']
> > s[person]['attributes'][attribute]['high score'] = \
> > dictPeople['attributes'][attribute]['high score']
> > s[person]['attributes'][attribute]['time'] = \
> > dictPeople['attributes'][attribute]['time']
> > It turns out, I get the key error because I am not allowed to reference a
> > key/value pair the same way that I can with a dictionary. However, the
> > crazy thing is that I can call values in the db file using the same exact
> > format when trying to write.
> >
> > For example: I can read data from the .db file using:
> >
> > x = s['person_1']['name']
> > print(x)
> > BUT! I cannot write to that .db file using that exact format or I get an
> > invalid key error. Makes no sense!
> >
> > s['person_1']['name'] = 'Bob'
> > # Returns invalid key entry.  Makes no sense.
> > Therefore, I tried to extract data and populate the db file using the
> > following:
> >
> > s[person] = {   'name': dictPeople.person_1['name'],
> > 'type': dictPeople.person_1['type'],
> > for attribute in range(0, len(dictPeople['attributes'][attribute])):
> > ['game':  dictPeople['attributes'][attribute]['game'],
> > 'high score': dictPeople['attributes'][attribute]['high score'],
> > 'time': dictPeople['attributes'][attribute]['time']]
> >
> > }
> > But, this obvously doesn't work because of the for loop. How can I do
> > this?
> >
> > -I am trying to figure out how to extract data from the dictionary
> > dictPeople.py file and store it in the people.db file.
> > -I am trying to add new people to the people.db file as more people
> become
> > available.
> > -I need to use the for loop because of the 50+ attributes I need to add.
> > -My future steps would be to modify some of the data values that I
> extract
> > and used to populate the people.db file, but my first step is to, at
> > least, extract, and then populate the people.db file.
> >
> > Any help or guidance is greatly appreciated.  Thank you for your time and
> > reading my question.
>
> You don't need these loops. The problem is that when you read the dict from
> the db
>
> db = shelve.open(...)
> person = db["person_1"]
>
> person is a Python object completely independent of the shelve and the
> shelve has no way to trace changes to that object:
>
> $ python3
> Python 3.4.3 (default, Oct 14 2015, 20:28:29)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import shelve
> >>> db = shelve.open("tmp.shelve")
> >>> person_1 = { 'name': 'Bob', 'type': 'employee', 'attributes':
> ... [{'game': 'basketball', 'high score': '100', 'time': '3.34'},
> ... {'game': 'bridge', 'high score': '10', 'time': '30.34'},
> ... {'game': 'foosball', 'high score': '2', 'time': '24'}]
> ... }
> >>> db["person_1"] = person_1
> >>> db["person_1"]["age"] = 42
> >>> db.close()
> >>> db = shelve.open("tmp.shelve")
> >>> db["person_1"]
> {'name': 'Bob', 'type': 'employee', 'attributes

Re: Meaning and purpose of the Subject field

2015-12-21 Thread Random832
Cameron Simpson  writes:
> Besides, changing the Subject line is _supposed_ to break the
> threading in these contexts: such clients clearly consider the
> discussion topic (subject) as sufficient definition of a thread, and
> changing the topic should imply a new thread to such simplistic
> clients.

This makes sense for the change from "old" to "new (was: old)",
which nobody was advocating against (after all, there's semantic
content - they wouldn't have changed the subject line if they
didn't consider it a new discussion topic), but I think there is
a reasonable argument that changing it a second time from
"new (was: old)" to "new" is frivolous.

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


Newbie XML problem

2015-12-21 Thread KP

>From my first foray into XML with Python:

I would like to retrieve this list from the XML upon searching for the 'config' 
with id attribute = 'B'


config = {id: 1, canvas: (3840, 1024), comment: "a comment",
 {id: 4, gate: 3, (0,0, 1280, 1024)},   
 {id: 5, gate: 2, (1280, 0, 2560, 1024)},
 {id: 6, gate: 1, (2560, 0, 3840, 1024)}}

I have started to use this code - but this is beginning to feel very 
non-elegant; not the cool Python code I usually see...

import xml.etree.ElementTree as ET

tree   = ET.parse('master.xml')
master = tree.getroot()

for config in master:
if config.attrib['id'] == 'B':
...  

Thanks for any help!






3840,1024
"bla"

1
6
0,0,1280,1024


2
5
1280,0,2560,1024


3
4
2560,0,3840,1024



3840,1024
"a comment"

4
3
0,0,1280,1024


5
2
1280,0,2560,1024


6
1
2560,0,3840,1024



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


Re: Newbie XML problem

2015-12-21 Thread Miki Tebeka
Hi,

> config = {id: 1, canvas: (3840, 1024), comment: "a comment",
>  {id: 4, gate: 3, (0,0, 1280, 1024)},   
>  {id: 5, gate: 2, (1280, 0, 2560, 1024)},
>  {id: 6, gate: 1, (2560, 0, 3840, 1024)}}
This is not valid Python. Are you trying to have a list of dicts?

> I have started to use this code - but this is beginning to feel very 
> non-elegant; not the cool Python code I usually see...
ElementTree supports XPATH, using this and some list comprehension you do 
things a little more easily. For example:

cfg = root.find('config[@id="B"]')
for panel in cfg.findall('panel'):
panels.append([{elem.tag: elem.text} for elem in panel])

You'll need to do some parsing for the coordinates and handle canvas and 
comments separately.
  
HTH,
Miki
-- 
https://mail.python.org/mailman/listinfo/python-list