Re: Newbie: Check first two non-whitespace characters

2015-12-31 Thread Denis McMahon
x != ''][0:3] == ['(', '(', '(']: # string starts '(((' -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Converting py files to .exe and .dmg

2015-12-28 Thread Denis McMahon
ython interpreter on the machine they wish to execute them on. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: return from function

2015-12-22 Thread Denis McMahon
turn statement might help in returning a value. When you recurse back into a function you still need to return the result of the recursion. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

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

2015-12-22 Thread Denis McMahon
nd you've managed to reach line 6194 without going through that block. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-20 Thread Denis McMahon
udent on this course, perhaps they are setting exercises for which they have not previously provided the necessary tuition. If that is the case, I suggest you ask them to reimburse your course fees, and then go and find better tutors. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Hangman Code.

2015-12-17 Thread Denis McMahon
variable value to prompt for the next player. After each player takes a turn, add 1 to the current player. If this is greater than the number of players, set it back to 1. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Why my image is in bad quality ?

2015-12-16 Thread Denis McMahon
idth*20,height*20), Image.ANTIALIAS) This appears to attempt to extrapolate 400 pixels from each pixel in the original image. That only works on TV crime dramas, you can't do it in real life. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Python variable assigning problems...

2015-12-10 Thread Denis McMahon
you'd like to post a short self contained example of the problem here instead. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a way to set several list elements a same value with one line code

2015-12-03 Thread Denis McMahon
e above three line codes are what I guess (I forgot the original > tutorial > now). Do you remember there is such a list application? bb = [ for i in range()] will create bb as a list of size whatever elements each of which is eg: >>> bb = [ ['a'] for i in range(4)] &g

Re: filter a list of strings

2015-12-03 Thread Denis McMahon
] def isgood(item) for thing in badthings: if thing in item: return False return True -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: stuff and nonsense

2015-12-02 Thread Denis McMahon
On Thu, 03 Dec 2015 01:46:44 +0100, Laura Creighton wrote: > In a message of Wed, 02 Dec 2015 22:51:13 +0000, Denis McMahon writes: >>On Wed, 02 Dec 2015 11:32:25 -0600, Ian Kelly wrote: >> >>> In what way is discussion of a tangential topic feeding the troll? &g

Re: stuff and nonsense

2015-12-02 Thread Denis McMahon
ternet search engines because of the way newsgroups get gated to websites. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Denis McMahon
On Tue, 01 Dec 2015 14:44:38 -0600, Ian Kelly wrote: > On Tue, Dec 1, 2015 at 2:32 PM, Denis McMahon > wrote: >> On Tue, 01 Dec 2015 03:32:31 +, MRAB wrote: >> >>> In the case of: >>> >>> tup[1] += [6, 7] >>> >>> what it

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Denis McMahon
On Tue, 01 Dec 2015 16:18:49 -0500, Terry Reedy wrote: > On 12/1/2015 3:32 PM, Denis McMahon wrote: >> On Tue, 01 Dec 2015 03:32:31 +, MRAB wrote: >> >>> In the case of: >>> >>> tup[1] += [6, 7] >>> >>> what it

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Denis McMahon
ts" or "license" for more information. >>> tup = [1,2,3],[4,5,6] >>> tup ([1, 2, 3], [4, 5, 6]) >>> tup[1] [4, 5, 6] >>> tup[1] += [7,8,9] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not su

Re: I can't understand re.sub

2015-11-29 Thread Denis McMahon
return 'hammer' if match == 'cat': return 'dog' if match == 'tree': return 'fence' return match with open("input.txt","r") as inf, open("output.txt","w") as ouf: line = inf.readline() line = patt.sub(replfunc, line) ouf.write(line) (also not tested) -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: New JSON encoding method proposal for custom objects

2015-11-29 Thread Denis McMahon
nd secondly there's no mechanism in json that tells you what class of object you have. So you may have a __json_dumps__ that will dump your object out to a json string representation, but then how does json.loads recognise that it's loading your object to call your object's

Re: Help with this program???

2015-11-27 Thread Denis McMahon
name (first and last), student number, and mark out of 100 for each student; 4. Uses regular expressions or similar mechanisms to ensure the data appears valid. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: reading from a txt file

2015-11-26 Thread Denis McMahon
u define a string? Is it just a line with the spaces removed? >>> "".join("this is a teststring my friends".split(" ")) 'thisisateststringmyfriends' -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: read 4D binary data

2015-11-26 Thread Denis McMahon
point (given by lat and lon) at that time. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Screen scraper to get all 'a title' elements

2015-11-26 Thread Denis McMahon
) if 'class' in p.attrs] Then you can do this for thing in stuff: print thing (Python 2.7) This may be adaptable to your requirement. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Getting math scores (Dictionary inside dictionary)

2015-11-24 Thread Denis McMahon
": 13} > } > > How do you get gengyang's maths scores ? I refer to my previous answer. Open a web browser and google "python dictionary" -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Returning a result from 3 items in a list

2015-11-24 Thread Denis McMahon
n that > list and returns Jordan's results i.e. (12) ? You open a web browser and google for "python dictionary" -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread Denis McMahon
for anything useful, because it will just use all the memory up. So perhaps you need to express your question in a better manner. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: String format - resolve placeholders names

2015-11-20 Thread Denis McMahon
t; ... > ('', 'who', '', None) > (' likes ', 'what', '', None) Or even: >>> s = "{who} likes {what}" >>> d = {'who': "Adam", 'what': "ants"} >>> keys = [

Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread Denis McMahon
ass_='lister-list'): for link in item.find_all('a'): # write link to file # close file Alternatively, use the with form: with open("blah","wb") as text_file: for item in soup.find_all(class_='lister-list'): for link in item

Re: Plotting timeseries from a csv file using matplotlib

2015-11-13 Thread Denis McMahon
for k in keybits: del row[k] plotdata[key] = row This generates a dictionary (plotdata) keyed by the key tuples where the value for each key is a dictionary of 0:0n : value -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about math.pi is mutable

2015-11-13 Thread Denis McMahon
g about supposed "real names". TPEL has been trolling html, php and javascript newsgroups for years, recently he seems to have discovered python newsgroups. :( -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: new to python, help please !!

2015-11-12 Thread Denis McMahon
provide executable tools at the OS level which are more efficient than anything you will write in a scripting language. Lesson 1 of computing. Use the right tool for the job. Writing a new program is not always the right tool. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.or

Re: new to python, help please !!

2015-11-12 Thread Denis McMahon
e, the execution time varies with the size of the datafiles. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Extracting and summing student scores from a JSON file using Python 2.7.10

2015-11-09 Thread Denis McMahon
rage of', students, 'scores is', sumscore / students It was trivial to generate: Sum of 50 scores is 3028 Average of 50 scores is 60 -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Getting response by email reply message

2015-11-09 Thread Denis McMahon
er, I > can read the messages from there from time to time. Read more carefully! The earlier poster suggested options that would work if you set up your own server, or already had one. You can poll your gmail server using pop3 as the earlier reply suggested. You may need to configure some op

Re: Regular expressions

2015-11-03 Thread Denis McMahon
er() for i in range(100): x = "test *"[-1] == "*" elapsed = timeit.default_timer() - start_time print "char compare, true", elapsed RESULTS: re, false 2.4701731205 re, true 2.42048001289 compiled re, false 0.875837087631 compiled re, true 0.876382112503 char comp

Re: If one IF is satisfied, skip the rest in the nest...

2015-10-21 Thread Denis McMahon
On Wed, 21 Oct 2015 20:07:21 +, Grant Edwards wrote: > On 2015-10-21, Denis McMahon wrote: >> On Wed, 21 Oct 2015 10:31:04 -0700, bigred04bd3 wrote: >> >>> So here what I have, I have a 3 IF's within the same level. If one IF >>> is satisfied, I

Re: If one IF is satisfied, skip the rest in the nest...

2015-10-21 Thread Denis McMahon
if c2: if c3: # c1 && c2 && c3 # 4 second open else: # c1 && c2 # 3 second open else: # only c1 # 2 second open Each condition only gets evaluated once. -- Denis McMahon, denismfmcma.

Re: Converting tuple of lists of variable length into dictionary

2015-10-18 Thread Denis McMahon
On Sun, 18 Oct 2015 20:38:26 +, Denis McMahon wrote: > On Sun, 18 Oct 2015 03:17:18 -0700, Beppe wrote: > >> hi to everybody, I must turn a tuple of lists into a dictionary. > > I went down a different path to Peter, and discovered something > perplexing: I just r

Re: Converting tuple of lists of variable length into dictionary

2015-10-18 Thread Denis McMahon
7;, 'c', 'd', 'e'], 'i': ['g', 'h'], 'h': ['g', 'i'], 'm': ['l', 'n', 'o'], 'l': ['m', 'n', 'o'], 'o': ['l', 'm', 'n'], 'n': ['l', 'm', 'o']} The second variant using, m = deepcopy(l).remove(i) fails thus: {'a': None, 'c': None, 'b': None, 'e': None, 'd': None, 'g': None, 'f': None, 'i': None, 'h': None, 'm': None, 'l': None, 'o': None, 'n': None} I'm not sure I understand why after m = deepcopy(l); m.remove(i); m is a different value to that which it as after m = deepcopy(l).remove(i). -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: pip problem

2015-10-16 Thread Denis McMahon
e all the permissions needed to write to the directories you're asking it to put files in? Did you run the installation process with those permissions? -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: How to repeat a loop once it is finished

2015-10-15 Thread Denis McMahon
stop or end to exit: ") print("you entered: ", x) if x in ["stop","quit","end"]: stop = True print("Finished now") -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: How to repeat a loop once it is finished

2015-10-15 Thread Denis McMahon
t; before you ask questions about it, then that would be even better. > Knowing what piece of code would also help us to help you. As a starter > here is a small piece of code. > > a = 1 > > Is that adequate? If not, perhaps: b = [c for c in range(20)] d = {e:b for e in

Re: Trouble running

2015-10-07 Thread Denis McMahon
wand. It should work now. If it still doesn't work, please provide more details about the problem. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Finding Blank Columns in CSV

2015-10-05 Thread Denis McMahon
i]: if len(row[i]) == 0: flags[i] = True else: blanks = True if not blanks: break -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: function code snippet that has function calls I have never seen before. How does it work.

2015-10-03 Thread Denis McMahon
unB(x, y): return (x-y) # this line # print(funA(4,funB(2,3), funB(3,2))) # can be written as the following 4 lines: a = funB(2, 3) # 2 - 3 -> -1 b = funB(3, 2) # 3 - 2 -> 1 c = funA(4, a, b) # (4 + -1) * 1 -> 3 print(c) # 3 -- Denis McMahon, denismfmcma...@gmail.com -- https

Re: Python 3.5.0 (32-bit) Setup error

2015-10-02 Thread Denis McMahon
u have given, I have waved my magic wand. If this didn't work, the information you supplied was insufficient. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about regular expression

2015-10-02 Thread Denis McMahon
On Wed, 30 Sep 2015 23:30:47 +, Denis McMahon wrote: > On Wed, 30 Sep 2015 11:34:04 -0700, massi_srb wrote: > >> firstly the description of my problem. I have a string in the following >> form: . > > The way I solved this was to: > > 1) replace all the

Re: Question about regular expression

2015-10-01 Thread Denis McMahon
(a list because I want to be able to modify it) setting d[word][n] = int(num) for each num element (numpatt.match(thing)) with n depending on whether it was the first or second num following the previous word then: d = {x:tuple(d[x]) for x in d} to convert the lists in the new dic to tuples

Re: Question about regular expression

2015-10-01 Thread Denis McMahon
= data_tuple Please don't top post. What happens if there's more whitespace than you allow for preceding a '(' or following a ',', or if there's whitespace following '('? -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about regular expression

2015-09-30 Thread Denis McMahon
) alice tom (1, 4) peter (2) andrew(3,4) janet( 7,6 ) james ( 7 ) mike ( 9 )" d = {'mike': (9, 0), 'janet': (7, 6), 'james': (7, 0), 'jim': (1, 0), 'andrew': (3, 4), 'alice': (0, 0), 'tom': (1, 4), 'peter': (2,

Re: Error code 0x80070570

2015-09-30 Thread Denis McMahon
On Wed, 30 Sep 2015 23:06:13 +0530, Rusiri Jayalath wrote: > Error code 0x80070570 appears when installing python 3.5.0 (32-bit) > setup for my windows 8.1 system. Please help me to solve this problem. This seems to be a windows error, not a python issue. Try google. -- Denis M

Re: Check if a given value is out of certain range

2015-09-29 Thread Denis McMahon
On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > Is there any similar elegant way to check if a value is out of certain > range? What about: if not (0 < x < 10): -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Denis McMahon
o convert km to miles def convert_km_mi(km): return convert_float_a_b(km, 0.6214) # now call main to kick it all off main() -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Python, convert an integer into an index?

2015-09-23 Thread Denis McMahon
and the intent of the question you meant to ask, you might find that the following code does something interesting: x = 9876543210 y = [] while x > 0: y.append(x % 10) x = int(x / 10) y = list(reversed(y)) print y -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org

Re: Einstein's Riddle

2015-09-19 Thread Denis McMahon
essage, it's going to nuke Beijing and Moscow . (I really really really hope that this is indeed fiction!) -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Add items from a python list to a javascript array

2015-09-19 Thread Denis McMahon
t;/a/b.htm", "/a/c.htm"] page = "\n" fmt = "var frames=Array({});\n" page += fmt.format(",".join(map(lambda x:'"'+x+'"', files))) page += "\n" print page -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Phone Tree

2015-09-13 Thread Denis McMahon
ut which question leads to which next question. This way also makes for an interesting talking point about separating data and code, especially given the multiple if statements issue. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: convert element in a list to float

2015-09-13 Thread Denis McMahon
into a float, and (I think) should leave all others as they are. It users a helper function and a list comprehension. >>> def tofloat(x): ... try: ... return float(x) ... except ValueError: ... return None ... >>> l = [ '300', '"N"', '1140', '"E"' ] >>> l = [ tofloat(x) or x for x in l ] >>> l [300.0, '"N"', 1140.0, '"E"'] -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: How to use the returned telnet object after creating the telnet session.

2015-09-13 Thread Denis McMahon
> Now in the calling function If I use that object to read or write to > terminal I'm getting ERROR "AttributeError: 'NoneType' object has no > attribute 'read_very_eager'". My best guess would be that something failed and has returned None instead of

Re: Random MAC generator error

2015-09-12 Thread Denis McMahon
esult: 00:16:3e:21:da:a4 00:16:3e:57:be:d2 00:16:3e:6b:e5:ae 00:16:3e:54:0e:f0 00:16:3e:57:5e:50 00:16:3e:21:99:6b 00:16:3e:12:e6:05 00:16:3e:53:02:6d 00:16:3e:79:17:1b 00:16:3e:02:ff:b8 00:16:3e:4e:ff:0d Observation: No point in declaring mac1 as global in the global scope. Is it possible that y

Re: Context-aware return

2015-09-10 Thread Denis McMahon
x == func() Would you expect the last two calls to func() to return 999 or "Awesome"? Why? What is the material difference if any between interpreter (a) displaying the return value and (b) comparing the return value with another value. Debugging nightmare! -- Denis McMahon, den

Re: Hi am new to python

2015-09-09 Thread Denis McMahon
= sum(list_a) print (s) And if you only want to display the answer: print (sum(list_a)) -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Lesson 39 of Learning Python the Hard Way hangs

2015-09-09 Thread Denis McMahon
On Wed, 09 Sep 2015 20:45:57 +, John Gordon wrote: > In any case, I saved your code and ran it, and did not get an error. +1 I think "Execution Succesful!" might be coming from his IDE? -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: python

2015-09-07 Thread Denis McMahon
On Sun, 06 Sep 2015 16:09:42 -0700, babi pepek wrote: > I wand update update There, now you have update. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Can anyone help me run python scripts with http.server?

2015-09-06 Thread Denis McMahon
On Sun, 06 Sep 2015 23:23:14 +1000, Chris Angelico wrote: > WSGIScriptAlias / /path/to/scripts/MinstrelHall/mh.wsgi One wonders if the OP has mod_wsgi installed. https://code.google.com/p/modwsgi/wiki/WhereToGetHelp might be useful too. -- Denis McMahon, denismfmcma...@gmail.com -- ht

Re: How to compare lists

2015-09-01 Thread Denis McMahon
expect, you could come back here and post your code with a description of what you think it should do, what it actually does, and why you think that's wrong, and we'll try and help you fix. What we won't do is write your application from scratch. -- Denis McMahon, denismfmcma

Re: Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread Denis McMahon
receiving and how the xml nodes and their attributes and values should be mapped into the csv file you want to create. Unfortunately I don't think that there is a single standard mechanism for doing that bit, although there are some tools and libraries that can help. -- Denis McMahon, denism

Re: How to model government organization hierarchies so that the list can expand and compress

2015-08-15 Thread Denis McMahon
bordinates' : ['army', 'navy', 'air force', 'jsoc'] }, 'navy' : { 'superiors' : ['jcs', 'nsa', 'cia'], 'subordinates' : ['seals', 'marines', 'pacific fleet' ] }, } The multiple parenting means that you need to use something as references. You can't represent the hierarchy as a simple tree, because in a simple tree a node only has one parent. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: AttributeError

2015-08-13 Thread Denis McMahon
e I posted may need the addition of a line something like: if line.startswith("From "): in a relevant position, as well as additional indenting to take account of that addition. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: AttributeError

2015-08-13 Thread Denis McMahon
commands of the actual text elements that you want to extract. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: AttributeError

2015-08-12 Thread Denis McMahon
ours record always at position Y in the timestamp. c = [0 for i in range(24)] f = open(filename,'r') for l in f: h = int(l.strip().split()[X].split(':')[Y]) c[h] = c[h] + 1 f.close() for i in range(24): print '{:02d} {}'.format(i, c[i]) -- D

Re: AttributeError

2015-08-12 Thread Denis McMahon
can you please transfer to floor-scrubbing 101. [1] You have repeatedly ignored advice and instructions that you have been given. This is de-facto proof that you are not capable of learning to program computers. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: AttributeError

2015-08-12 Thread Denis McMahon
On Wed, 12 Aug 2015 09:29:50 -0700, Ltc Hotspot wrote: > Using the attached file of a diagram as a frame, why is there an > attribute message? Perhaps you should read the message. It's very clear. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/list

Re: AttributeError

2015-08-12 Thread Denis McMahon
rse the strings in the log file(s), incrementing counts[x] where x is the hour field of the timestamp. Then I'd create a list of tuples: ncounts = [(k,v) for k,v in counts.items()] sort it by the hour field: ncounts.sort(key = lambda x: x[0]) and print it: for x in ncounts: pr

Re: AttributeError

2015-08-12 Thread Denis McMahon
unt.sort(reverse=True) print key,val ncount is a single key-value pair. Why are you trying to sort ncount? Do you want results ordered by count? First, change your dictionary into a list of tuples: ncount = [(a,c) for a,c in count.items()] Then sort ncount on the second field of the tuple: ncount

Re: Logical Query JSON

2015-07-31 Thread Denis McMahon
too hard. You can construct the json query syntax fairly easily from python once you understand it: >>> import json >>> query = json.dumps( { "$and":[ { "$gt": {"age": 5} }, { "$not": {"name": "curly"} } ] } ) >>> query '{"$and": [{"$gt": {"age": 5}}, {"$not": {"name": "curly"}}]}' -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Logical Query JSON

2015-07-30 Thread Denis McMahon
to a database to see what comes out. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Find Minimum for element in multiple dimensional array

2015-07-23 Thread Denis McMahon
put.csv", "wb") as f: writer = csv.writer(f) writer.writerows(tmp.values()) and lo: $ cat output.csv a,15 c,18 b,38 $ -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: unexpected output while using list(and nested dictionary)

2015-07-22 Thread Denis McMahon
Ingress with a new single element list sg from makesg. I suspect you've refactored some code from processing a list of things inside a function to processing them in the main body, or vice versa, or have just got confused about what you're processing where. I suggest that you rename y

flipping string order

2015-07-19 Thread Denis McMahon
On Sun, 19 Jul 2015 17:35:03 +0100, MRAB wrote: > rsplit -> one line. def lastWordFirst(s): return " ".join(reversed(s.rsplit(" ", 1))) -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Need assistance

2015-07-18 Thread Denis McMahon
On Sat, 18 Jul 2015 12:35:10 +0200, Sibylle Koczian wrote: > Am 18.07.2015 um 02:40 schrieb Denis McMahon: >> Having a list of words, get a copy of the list in reverse order. See >> the reversed function (and maybe the list function). > That won't really help, because the

Re: Need assistance

2015-07-17 Thread Denis McMahon
able to a list. To join the elements of a list into a string, see the join method of strings. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: how to fix TypeError: format requires a mapping

2015-07-01 Thread Denis McMahon
ot;]""" % (row) > result_rows.append(formatted) > > print(',\n'.join(result_rows)) > > > clean_json(data) I assume you want the output as json. The solution may be to put the data into a suitable structure and dump the structure to json.

Re: "normalizing" a value

2015-07-01 Thread Denis McMahon
in your current code. Is this what you want? You could try the following: # step 1, limit x to the range -50 .. 50 if x < -50: x = -50.0 ix x >= 50: x = 50.0 # step 2, scale x to the range 0 .. 12 x = x * 0.12 + 6.0 If you want an integer value, you need to determine which method

Re: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)

2015-06-29 Thread Denis McMahon
On Sun, 28 Jun 2015 17:07:00 -0700, Ned Batchelder wrote: > On Sunday, June 28, 2015 at 5:02:19 PM UTC-4, Denis McMahon wrote: >> >> string 3 >> string 2 >> string 1 >> >> Each is just a member of the collection things, the xml does >> not

Re: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)

2015-06-28 Thread Denis McMahon
On Sun, 28 Jun 2015 09:46:36 +0200, Stefan Behnel wrote: > Denis McMahon schrieb am 26.06.2015 um 09:44: >> xml data is an unordered list, and are trying to assign an order to it. >> >> If the xml data was ordered, either each tag would be different, or >> each

Re: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)

2015-06-26 Thread Denis McMahon
you later use the xml. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: JSON Object to CSV File Troubleshooting

2015-06-22 Thread Denis McMahon
g that object, but I don't see that generating you one line of CSV for each Int32 in MonthDayCount. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: JSON Object to CSV File Troubleshooting

2015-06-21 Thread Denis McMahon
of what extracts from the XML are expected to be in which positions in the CSV. This is the sort of data conversion code I generally turn out in a day or so, it's hardly rocket science as long as you have a clear description of what is required. If you don't have a clear descrip

Re: JSON Object to CSV File Troubleshooting

2015-06-21 Thread Denis McMahon
ur requirement is for CSV, then you should be converting from XML to CSV. Also stop posting reams of code. No-one is reading it. If you have a specific error you need to fix, then post a shortest possible example of code that generates the error. This should never be more than about 10 lin

Re: JSON Object to CSV file

2015-06-21 Thread Denis McMahon
On Sun, 21 Jun 2015 06:57:01 -0700, sahluwalia wrote: > On Sunday, 21 June 2015 02:47:31 UTC-4, Denis McMahon wrote: >> On Wed, 17 Jun 2015 08:00:11 -0700, Saran A wrote: >> >> > I would like to have this JSON object written out to a CSV file so >> > that the ke

Re: JSON Object to CSV File Troubleshooting

2015-06-20 Thread Denis McMahon
en adequately describe it. At least, it seems that every time you do try and describe it either the data format or the task description changes. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: JSON Object to CSV File Troubleshooting

2015-06-20 Thread Denis McMahon
go straight from XML to CSV, there is little added value in using some arbitrary intermediate format unless you're actually going to use the data in the intermediate format for something other than converting to the final format. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail

Re: JSON Object to CSV file

2015-06-20 Thread Denis McMahon
> "CF": "Fee", Your json object seems to have the same key used for two elements at the same level, are you sure this is legal json? -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: How to inverse a particle emitter

2015-06-07 Thread Denis McMahon
e inside some simulation environment, then the best place to look is probably forums dedicated to that simulation environment. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: What is considered an "advanced" topic in Python?

2015-06-01 Thread Denis McMahon
ng (IMO) basic python programming skills in doing so. I guess that makes OOP / classes the advanced topic in my system. I don't consider "using library x to do y" as advanced python, it's just gluing together existing functions with your own basic programming, no matter wheth

Re: Where is 'palindrome' defined?

2015-06-01 Thread Denis McMahon
Now you also know that the error message: "NameError: name '' is not defined" means that you might have spelled differently on the line in the error message to the word you meant, so next time you see this error message you know to carefully check the spellings of function name

Re: What use for reversed()?

2015-05-31 Thread Denis McMahon
t() or create a list from reversed and then join the result: $ python Python 2.7.3 (default, Dec 18 2014, 19:10:20) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "".join(list(reversed(&qu

Re: Are there any other better ways to access a single bit of string of digits?

2015-05-31 Thread Denis McMahon
ulate them as numbers, not strings. def bing(n): n = int(n.replace("_", ""), base=16) # convert to numbers if n > 0x7fff:# if 0x8000 or more n = n + 0x0400# add 0x0400 return n # and retur

Re: Logic problem: need better logic for desired thruth table.

2015-05-28 Thread Denis McMahon
oldown or (not (BotWaitForCooldown or > CooldownDetected)) Nope, it simplifies to: BotWaitForCooldown or not CooldownDetected -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Decoding JSON file using python

2015-05-28 Thread Denis McMahon
On Wed, 27 May 2015 15:23:31 -0700, Karthik Sharma wrote: > The JSON structure is valid as shown by http://jsonlint.com/ Not when I paste it in it's not. The "data" attribute is an unterminated string and is not followed by a comma. -- Denis McMahon, denismfmcma...@g

Re: Decoding JSON file using python

2015-05-28 Thread Denis McMahon
e is a json string, then data maps to a list / array data[0] maps to an object / dictionary data[0]["Message"] maps to the string literal "tdetails" data[0]["attr_name"] maps to a string representation of a json ob with another level of escaping. That string can then be loaded, eg: attr_name = json.loads(data[0]["attr_name"]) See: http:/www.sined.co.uk/python/nested_json.py.txt -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

  1   2   3   4   5   >