Re: [Tutor] unittest difficulty

2017-07-19 Thread Japhy Bartlett
Is `0.0` the troublesome float here? On Wed, Jul 19, 2017 at 7:35 AM, Shall, Sydney wrote: > I am learning to use unittest. > > I have written a program that runs as it should. > 247 tests give me a satisfactory answer. > > I have now added one more test and I get an error which I do not > un

Re: [Tutor] Python - help with something most essential

2017-06-10 Thread Japhy Bartlett
It's really awkward the way you're using Counter here... you're making new instances in every lambda (which is not great for memory usage), and then not actually using the Counter functionality: return sum(1 for _ in filter(lambda x: Counter(word) == Counter(x.strip()), fileContent)) (the who

Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread Japhy Bartlett
The only legal concern is if you're copying challenges directly from the sites; someone has some sort of ownership and copyright on the code and description. Don't copy / paste anything and you'll be fine. If you do, check the license first (it may be open source). On Fri, Jun 2, 2017 at 12:2

Re: [Tutor] Python application with same name as its corresponding project

2015-07-31 Thread Japhy Bartlett
Like Chris mentions, usually you don't write your own stuff in /bin/. To make what you've written work anyhow, you can run them from inside /ProjectParent/, not from inside /ProjectParent/bin/. eg, `python bin/projectgendocs.py` On Fri, Jul 31, 2015 at 1:16 PM, Chris Warrick wrote: > On 31 Jul

Re: [Tutor] Dynamic naming of lists

2015-03-31 Thread Japhy Bartlett
Ian - Note that if all your keys are named 'broadcast', the dictionary approach is probably not going to work. You'll end up with something like: { 'broadcast': 'last_value_in_the_list' } On Tue, Mar 31, 2015 at 10:56 AM, Ian D wrote: > Ok Thanks a lot. And sadly not a typo, my bad logic ov

Re: [Tutor] (no subject)

2014-11-29 Thread Japhy Bartlett
It looks like this is a pretty common stumbling block, and you need to call `pygame.font.init()` before the code you pasted. Also.. the way you've pasted that code has added '||' all over the place. Not sure what's going on there (some sort of tabs/spaces thing?), but it makes it extremely hard to

Re: [Tutor] Code critique

2014-10-24 Thread Japhy Bartlett
out = stdout.read() if '3102EHD-Lanka-1108' in out: s.exec_command('export DISPLAY=:0.0; cd /Downloads/Hourly/win.sh') sftp = s.open_sftp() sftp.get('/Downloads/Hourly/3102EHD-01108/3102EHD-01108.png', '/Downloads/Hourly/3102EHD-01108.png') sftp.close() print

Re: [Tutor] Development of administration utility

2014-08-21 Thread Japhy Bartlett
You could definitely achieve that modularity, if the parent package knows (by convention) where to look for sub-modules. I'm not sure there's a built-in mechanism, unless you want to use 'import' in a clever way. It feels like that's more of a RPM/.deb challenge than a Python challenge. There ar

Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-20 Thread Japhy Bartlett
this forms a list of integers >>> [0]*5 [0, 0, 0, 0, 0] what I think you want is something like: >>> [[0] for i in range(5)] [[0], [0], [0], [0], [0]] (a list of lists) >>> foo = [[0] for i in range(5)] >>> foo[3].append('bar') >>> foo [[0], [0], [0], [0, 'bar'], [0]] On Wed, Aug 20, 2014 a

Re: [Tutor] While Loop and Threads

2014-07-15 Thread Japhy Bartlett
this construct: On Tue, Jul 15, 2014 at 5:09 AM, Oğuzhan Öğreden wrote: > > > while time_now < time_finish: # counter and count_until defined > somewhere above and > if g_threadStop.is_set() == False: > # return something or raise an exception to signal > ite

Re: [Tutor] sending email via SMTP: code review requested

2014-05-05 Thread Japhy Bartlett
If you get deeper into processing emails, you might check out http://lamsonproject.org/ . I wasn't fond of the whole thing, but if you dig into the src there is some pretty good code for handling malformed MIME structures and unicode issues in a sane way. On Mon, May 5, 2014 at 4:26 PM, Brian va

Re: [Tutor] sending email via SMTP: code review requested

2014-05-05 Thread Japhy Bartlett
The "from" quirk is because it gets parsed as a header, I think. Sending is pretty simple, you should be OK. It may be worth setting up an outgoing-only mail server like postfix that only listens in localhost, gmail can be fussy about quotas. On Sunday, May 4, 2014, Brian van den Broek wrote:

Re: [Tutor] OT: Coffeescript and Python

2013-09-06 Thread Japhy Bartlett
I worked on a project that used cofeescript with Django. You basically have to know javascript to debug it properly, so it didn't really save our team any time and we got rid of it as soon as we could. Obviously that's just anecdotal, YMMV! On Fri, Sep 6, 2013 at 5:47 AM, Alan Gauld wrote: > T

Re: [Tutor] How to present python experience (self-taught) to potential employer

2013-08-23 Thread Japhy Bartlett
Jing - You demonstrate skill at writing python by writing python. If you don't have data, write something to scrape data. If you seriously can't think of any problems or interesting side projects to solve in either of your fields, bluntly, you're almost certainly worthless as a researcher. Go b

Re: [Tutor] How to present python experience (self-taught) to potential employer

2013-08-23 Thread Japhy Bartlett
One project is fine, unless your competition has finished two. Start at least with one script in each language that you want on your resume that does some sort of analysis on a set of data. With all due respect to Amit, if you are going for academic work don't bother with tests or documentation,

Re: [Tutor] inconsistent destruction

2013-08-08 Thread Japhy Bartlett
you can either manually manage the memory with `del cnt` or let the built in memory management .. manage the memory. On Wed, Aug 7, 2013 at 10:54 PM, Jim Mooney wrote: > This bugs me for some reason. The final variable is saved in a for > loop but not in a list comprehension. It just seems to me

Re: [Tutor] POST MULTI PART DATA WITH PYTHON

2013-05-15 Thread Japhy Bartlett
In your code, you're not actually inserting the contents of the file into your MIME part (you're only constructing headers), which is why the content-length is not right. The 404 is probably the site detecting this as a script/robot/violation of their TOS and blocking you. Which you can probably

Re: [Tutor] writing effective unittests

2013-01-08 Thread Japhy Bartlett
The general idea is to write tests that use your code in realistic ways and check the results. So if you have a function that takes an input and returns a result, you write a test that passes that function an input checks the result. If some inputs should make it error, you write a test that chec

Re: [Tutor] Generating random alphanumeric codes

2012-07-04 Thread Japhy Bartlett
I've always liked uuid4 >>> from uuid import uuid4 >>> str(uuid4())[:4] '0ca6' On Tue, Jun 26, 2012 at 3:47 PM, Dave Angel wrote: > On 06/26/2012 03:47 PM, Martin A. Brown wrote: > > Hello, > > > > : Would anyone have tips on how to generate random 4-digit > > : alphanumeric codes in python?

Re: [Tutor] Game lag

2012-01-09 Thread Japhy Bartlett
If you made an effort to strip out parts of your code, it would probably show you where the bottlenecks are. You say that the large map is not the problem, but do you really know? On Jan 5, 2012, at 10:08 AM, Nate Lastname wrote: Thanks for the profilers - never had hear of 'em. Also, no, I

Re: [Tutor] Windows vs Linux processing speed.

2011-10-14 Thread Japhy Bartlett
In this situation, the network connection is almost certainly the bottleneck; maybe CPU speed, if they are drastically different, but it seems like you're running relatively comparable hardware. RAM is almost never a *speed* bottleneck, until you start working with datasets larger than you can ho

Re: [Tutor] Python Job Scheduling package

2011-10-14 Thread Japhy Bartlett
Is this a thing people would use? I've built this as part of a larger project.. do you think it'd be worth splitting out and polishing up? On Oct 14, 2011 3:55 AM, wrote: Have you thought about writing your own? Others have posted some useful links, but in all honesty you could hack something t

Re: [Tutor] Infinite Loop

2011-10-03 Thread Japhy Bartlett
If the guess is larger than the number, your code will never prompt for a new guess in the while loop. Try removing one indent on the input() line. On Sep 24, 2011 10:44 AM, "Cameron Macleod" wrote: Hi, I've been trying to code a simple guess my number game as a starter programming project bu

Re: [Tutor] Help - accumulator not working (Lea)

2011-04-16 Thread Japhy Bartlett
I think that here: >     expense = float(raw_input('Enter the next expense or 0 to finish $')) you want to use `expense +=` instead. Instead of adding it to the previous expenses, you're resetting the `expense` variable each time. I think there's some other things that won't behave as expec

Re: [Tutor] server used in python

2011-03-29 Thread Japhy Bartlett
I think tornado (http://tornadoweb.org) is one of the easiest server / frameworks to learn and work with. On Tue, Mar 29, 2011 at 4:21 AM, Alan Gauld wrote: > > "ema francis" wrote > >> I am learnning python for  3 months from now. I wanted to know how and >> what >> *server* is used in python w

Re: [Tutor] How to use a str object, to find the class in exact name?

2011-03-15 Thread Japhy Bartlett
I hate to jump on this one a little late, but even getattr() is kind of ghetto (though exec/eval is worse ;). For setting up shell scripts or CLIs, the usual route is the optparse module. - Japhy 2011/3/15 Yaşar Arabacı : > Thanks for excellent explanations. I almost got this working. I just hav

Re: [Tutor] creating classes while coding

2011-02-21 Thread Japhy Bartlett
I think OOP makes it easy for new programmers to set up programs, and it can make for some pretty neat English looking code, but a more functional approach generally makes for much leaner, faster performing code. I find them most useful when you have several functions that might need to share some

Re: [Tutor] 'Installing' Python at runtime? (Civilization)

2011-02-04 Thread Japhy Bartlett
a common approach is to embed python in a compiled binary On Thu, Feb 3, 2011 at 9:18 PM, Steven D'Aprano wrote: > Alan Gauld wrote: >> >> "C.Y. Ruhulessin" wrote >> >>> When I load up Civilization IV, a Firaxis game, the loading screen tells >>> me >>> "Loading Python". >>> >>> However, I can't

Re: [Tutor] Help listing directory timestamps and deleting directories

2011-01-24 Thread Japhy Bartlett
I would check that os.path.join(r,dir) is giving you the directory you think it is. - japhy On Mon, Jan 24, 2011 at 12:25 PM, bsd...@gmail.com wrote: > Hi, hoping for some help here. I've been trying to write a python script > (complete newb) and have spent several days trying to get this right

Re: [Tutor] Help on RE

2011-01-23 Thread Japhy Bartlett
it's a bug in your regex - you want something like "-?\d+" - japhy On Sat, Jan 22, 2011 at 7:38 PM, tee chwee liong wrote: > hi, > > i have a set of data and using re to extract it into array. however i only > get positive value, how to extract the whole value including the -ve sign? > For eg: >