Re: Average calculation Program *need help*

2016-05-12 Thread Martin A. Brown
gestion #3: -- Break the problem down even smaller (Rustom Mody appears to have beat me to the punch on that suggestion, so I'll just point to his email.) Hint #1: ---- What is the value of your variable totalScores each time through the loop? Does it ever get reset? Good luck with your degubbing! -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: redirecting stdout and stderr to /dev/null

2016-05-07 Thread Martin A. Brown
en(cmd, stdout=devnull, stderr=devnull) retcode = proc.wait() if retcode != 0: raise FlamingHorribleDeath You will have to define FlamingHorribleDeath or figure out what you want to do in the event of the various different types of failureif you don't then, you'll just see this: NameError: name 'FlamingHorribleDeath' is not defined Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?]

2016-04-29 Thread Martin A. Brown
ontent.com/tLDP/python-tldp/master/docs/ldptool-man.rst [7] https://raw.githubusercontent.com/DavidGamba/grepp/master/grepp.adoc -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: How to track files processed

2016-04-18 Thread Martin A. Brown
e(fname) logger.info("Computed MD5 hash digest %s", digest) print('%s %s' % (digest, fname,)) return os.EX_OK if __name__ == '__main__': if len(sys.argv) == 1: sys.exit(main(os.getcwd())) else: sys.exit(main(sys.argv[1])) # -- end of file -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Looking for feedback on weighted voting algorithm

2016-04-14 Thread Martin A. Brown
tion: votes = [72, 72, 72, 72, 96, 96, 96, 48, 48, 53, 26, 26, 26, 26, 31, 31, 31, 68, 68, 91] But, don't bother! Your function can handle votes that have a float weight: >>> weight([(4, 1.3), (1, 1),]) 2.695652173913044 Have fun! -Martin -- Martin A. Brow

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Martin A. Brown
UCCESS in every program. Clearly, in my above example the contents of the run() function look strange. Usually it has more different kinds of stuff in it. Anyway, best of luck! -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: one-element tuples

2016-04-10 Thread Martin A. Brown
string. >>> a = '"string1",' >>> ea = eval(a) >>> len(ea), type(ea) (1, ) >>> b = '"string1","string2",' >>> eb = eval(b) >>> len(eb), type(eb) (2, ) >>> c = '"string1","string2","string3",' >>> ec = eval(c) >>> len(ec), type(ec) (3, ) Good luck in your continuing Python explorations, -Martin P.S. Where do your double-quoted strings come from, anyway? -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Set type for datetime intervals

2016-04-06 Thread Martin A. Brown
surprisingly, it does. > >Thank you! It is so much better than the one I have created. >Possibly I'll delete my own module from pypi. :-) I'm glad to have been able to help, László. And, even if you don't delete your new module, you have certainly stimulated quite a discus

Re: Set type for datetime intervals

2016-04-04 Thread Martin A. Brown
It occurred to me this morning, after you posted your new library: https://pypi.python.org/pypi/intervaltree This handles overlapping ranges nicely and provides some tools for managing them. Before posting this, I checked that it works with datetime types, and, unsurprisingly, it does. Hap

Re: how to optimize the below code with a helper function

2016-04-04 Thread Martin A. Brown
= set [test100] # -- no way to capture baddr=lin_02; must reproduce contents of lin_02 object = baddr offset = 100 size = 5 optype = set -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: how to optimize the below code with a helper function

2016-04-04 Thread Martin A. Brown
run_tool(logfile, **kw): logger.info('%s would execute with %r', logfile, kw) def addLogFilename(d, logdir): '''put the logfile name into the test case data dictionary''' for casename, args in d.items(): args['logfile'] = os.path.join(logdir, casename + '.log') return d def main(): testcases = createTestCases(LOG_DIR) get_baddr = dict() for casename, kw in testcases.items(): # -- yank the logfile name out of the dictionary, before calling func logfile = kw.pop('logfile') get_baddr[casename] = run_tool(logfile, **kw) if __name__ == '__main__': main() # -- end of file -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Path when reading an external file

2016-03-28 Thread Martin A. Brown
uot; > using __file__ so that the program works wherever you launch > "python code.py" > > Is it the correct way to handle this problem ? Ayup, I would say so. My suggested technique: here = os.path.dirname(os.path.abspath(__file__)) foo = os.path.join(here, 'foo.txt

Re: Beginner Python Help

2016-03-19 Thread Martin A. Brown
cription, I'd give you this example for loop that produces the same outcome. list1 = list() for n in num.split(): list1.append(int(n)) The map function is quite useful, so it's a good one to learn early. Good luck, -Martin [0] https://docs.python.org/3/library/functions.html#input [1] https://mail.python.org/mailman/listinfo/tutor/ [2] https://docs.python.org/3/library/functions.html#map -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: retrieve key of only element in a dictionary (Python 3)

2016-03-19 Thread Martin A. Brown
ute__, __getitem__, __gt__, __init__, __iter__, __le__, __len__, __lt__, __ne__, __repr__, __setitem__ and __sizeof__ -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: retrieve key of only element in a dictionary (Python 3)

2016-03-18 Thread Martin A. Brown
I find the addition of a few characters makes this assignment much clearer to me. # -- if len(d) > 1, ValueError will be raised # (key,) = d.keys() And thank you for the reply Chris, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Perl to Python again

2016-03-11 Thread Martin A. Brown
ay benefit from: The Python Cookbook (O'Reilly) http://shop.oreilly.com/product/0636920027072.do Python Module of the Week https://pymotw.com/3/ I'm making those recommendations because I know and have used these and also because of your Perl background. Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: issue with csv module (subject module name spelling correction, too)

2016-03-11 Thread Martin A. Brown
and-formatting-parameters Judging from your example, you definitely want to use quoting=csv.QUOTE_NONE, because you don't want the module to do much more than split('\t'). Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Simple exercise

2016-03-10 Thread Martin A. Brown
.org/3/library/functions.html#zip Toy example: import string alpha = string.ascii_lowercase nums = range(len(alpha)) for N, A in zip(nums, alpha): print(N, A) Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Caching function results

2016-03-03 Thread Martin A. Brown
s.lru_cache can help you with how they solved the problem of mapping entry count to memory usage. Good luck, -Martin [0] https://docs.python.org/3/library/functools.html#functools.lru_cache -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: common mistakes in this simple program

2016-02-29 Thread Martin A. Brown
lauses to the above block with appropriate handling, or (re-)raising the caught exception. Comments on shelling out to other programs and using exceptions --- Exceptions are great for catching logic errors, type errors, filesystem err

Re: tcp networking question (CLOSE_WAIT)

2016-02-25 Thread Martin A. Brown
True >loop. so the socket will keep in close_wait > >I fond the issue. it's my own stupid issue. >i did "continue" if no data received. >just break from it then it will be fine Well, I'm glad you found the issue. Best of luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: tcp networking question (CLOSE_WAIT)

2016-02-25 Thread Martin A. Brown
g SO_REUSEADDR). This is the most likely problem. Suggestion: man 7 socket Look for SO_REUSEADDR. Then, apply what you have learned to your code. -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Network Simulator

2016-02-24 Thread Martin A. Brown
ub.com/jsommers/switchyard NS-3, the researcher's toolkit https://www.nsnam.org/ https://www.nsnam.org/wiki/Python_bindings Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: asyncio - run coroutine in the background

2016-02-20 Thread Martin A. Brown
tps://pypi.python.org/pypi/adns-python/1.2.1 And, there are Python bindings. I have been quite happy using the adns tools (and tools built on the Python bindings) for mass lookups (millions of DNS names). It works very nicely. Just sharing knowledge of an existing tool, -Martin -- Mart

Re: Make a unique filesystem path, without creating the file

2016-02-14 Thread Martin A. Brown
s of that method. Good luck, -Martin * I was tempted to joke about these two guarantees, but I think that undermines my basic message. To wit, you can probably rely on this naming technique about as much as you can rely on your system clock. I'll assume that you aren&

Re: Suggested datatype for getting latest information from log files

2016-02-11 Thread Martin A. Brown
): now = time.time() who = random.choice(players) marbles = random.randint(0, 100) record[who].append((marbles, now)) for whom, marblehistory in record.items(): print(whom, end=": ") pprint.pprint(marblehistory) if __name__ == '__main__': import sys if len(sys.argv) > 1: count = int(sys.argv[1]) else: count = 30 marblegame(count) # -- end of file -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Martin A. Brown
Run the code on the command-line. * How much time have you taken to work out what the interpreter is telling you? Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Martin A. Brown
make sure that you are running the same code that you are working on. Then, if you are still experiencing syntax errors, study the lines that the interpreter is complaining about. And, of course, send the list an email. Best of luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-05 Thread Martin A. Brown
yntax. Your code has, unfortunately, suffered a colonectomy. When you transplant a colon, it is more likely to function properly again. For example: except socket.error as e: Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-02-02 Thread Martin A. Brown
e incompetent hospital-radio trained Martin Brown (Stevens) P.P.S. In case it is not utterly clear, I am not the above author. -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: ignoring or replacing white lines in a diff

2016-01-14 Thread Martin A. Brown
*$' token 4: ./xml/name.xml token 5: test.xml Try this (untested): > cmd = ["diff", "-w", "-I", "^[[:space:]]*$", "./xml/%s.xml" % name, > "test.xml"] But, perhaps the xmldiff module will be what you want. -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Help on return type(?)

2016-01-09 Thread Martin A. Brown
the point nicely. * If you break the individual computations into functions, then you only run the specific computation when it's needed. In the original example, all of the computations were run AND then, one of the results was selected. It may not matter, since computers are so fast, but, practicing basic parsimony can avoid little obvious performance hazards like this. * In short, longer, but much much clearer. Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: raise None

2015-12-31 Thread Martin A. Brown
t;--- the first place we could detect it > File "spam", line 5, in _validate <--- where we actually detect it Yes, indeed! Our stock in trade. I never liked function 'that'. I much prefer function 'this'. -Martin Q: Who is Snow White's brother? A: Egg white. Get the yolk? -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Most space-efficient way to store log entries

2015-10-28 Thread Martin A. Brown
y sample log data must have been more homogeneous than the data on which I derived my mental bookmarks for textual compression efficiencies of around 15% for zlib and 12% for bz2. I have no mental bookmark for lzma yet, but 7% is an outrageously good compression ratio. -- Martin A. Brown http://linux-ip.net/ -- https://mail.python.org/mailman/listinfo/python-list