« first day (1708 days earlier)      last day (3239 days later) » 
00:00 - 17:0017:00 - 23:00

5:03 PM
how can I rename the single extracted file from the ZipFile class?
 
How can I start looking for index from the end?
.index('L', -1, 0) doesnt work
and it makes sense it doesn't
 
@AaronHall silicone is good too. btw with plastic you don't get same results, you must use soft plastic. as for everything a good tool is essential :) of course you might eat small particles of plastic. but your body doesn't absorb it. on the contrary it absorbs the micro particles of no-stick coatings which are carcinogenic.
 
@afonsomatos I don't think you can
 
@afonsomatos .rindex
 
@PaoloCasciello thanks
 
5:09 PM
Guys
----> 1 [].rindex

AttributeError: 'list' object has no attribute 'rindex'
 
i thought he was searching in a string sorry
>>> 'ABC'.rindex('B')
1
 
lol
 
Oh
 
I was searching in a string
Also, how can I get the 5 right most letters?
string = 'Hello o o o World'
 
Ugh, sorry
 
5:12 PM
string[-5:0] # doesnt work
 
s[-5:]
 
lol
 
@AaronHall thanks but why doesnt [-5:0] work?
 
@afonsomatos try None instead of 0
 
ooops. no it's not the same thing..... shame on me.. :D
 
5:14 PM
@AaronHall but why doesnt 0 work?
 
3
A: Reverse a Python string without omitting start and end slice

Aaron HallFrom the Python 2 source, this is defined with ternary expressions: defstart = *step < 0 ? length-1 : 0; defstop = *step < 0 ? -1 : length; So, when start and stop are not given, If step is negative: start is length - 1 stop is -1, (this is the C index, tricky to implement in Python, m...

Does that help?
 
@afonsomatos because 0 is the start of the string. you want from -5 to the end.
 
stop is the length when the step is positive.
s[given:None:positive] => replace None with len(s)
Make sense?
@afonsomatos did that help?
 
@AaronHall you are just telling me to put None, not telling WHY
@PaoloCasciello But shouldn't it go something like -5, -4, -3, -2, -1
 
I'm telling you how to explicitly give an argument that works too
 
5:22 PM
ok I got it from your answer
 
Not having an argument is the same as passing None
glad to help. I supplanted the earlier accepted answer.
brag brag
 
@afonsomatos indeed. but think about trying to cut arope.. from 5cm to... the start. you get nothing. :) now think about cutting it from 5cm untile it ends. omitting the right argument is "until it ends"
 
That answer will eventually become a Necromancer badge for me... but it looks like not today... :D
 
Rhubarb
 
grocery shopping, holden?
 
5:25 PM
And thanks for the good wishes
 
@PaoloCasciello thanks
 
checks cache of Necromancer badges
Nope, not enough...
 
@afonsomatos nm
 
packs them back into his soap-box
ok, guys, I'm off to tutor people in Python for free at the Learn Python NYC meetup group, held at the nicest workshare offices in the city.
I hope you all do good.
Answer lots of questions for people who aren't privileged enough to live near me. :D
 
5:31 PM
Rhubarb, @AaronHall. Keep up the good work
 
I was invited to help with the relief bus next weekend, I might go even if my wife can't make it. It does your soul good to get out and feed the homeless.
 
Certainly lets you feel fortunate
 
Also, although I'm omnivorous, veg gives me gas. No rabbit food for me. :D
 
"Your problem is not the collection name being a string, db[collection] where collection is a string is perfectly valid" Indeed, but db[collection] where both db and collection are strings isn't valid. The error in the question isn't caused by the insert method. — vaultah 5 secs ago
 
5:53 PM
I am less and less pleased with PyCharm
keeps bugging all the time and the shortcuts are always different from what I find online... even the bug tracker is tedious to use
I submitted 2 bugs to the tracker and didn't even get comment to the other...
I guess they will fix my bugs after 1 year :D
 
6:12 PM
Happy birthday @holdenweb
 
6:23 PM
I'm at the meetup, tea in hand - Office Hours are in session.
 
guys, I'm a little bit puzzled and I think you can help me
when I started learning at codecademy, they taught me I can put current time in the variable by calling .now() method of datetime. python 2.7 btw
when I do it here, it says now() is not a recognized method.
Has this changed maybe?
 
it is datetime.datetime.now()
 
oh, thanks a lot! :)
 
the tricky and annoying part is whether you do from datetime import datetime
or import datetime
 
6:34 PM
oh, I understand :)
 
if the former, you can use datetime.now(), the latter, and it is "datetime.datetime"
 
Another victim of poor naming.
 
Thank you! You just helped me finish my program, after weeks of struggle!
 
now, imo that is badly named module, but one would need to travel back in time 13 years to get it right :D
 
hahahahah good one :D
 
6:35 PM
too bad they didn't fix it for python 3 either
 
really puzzling, I have to admit
 
Gentlemen, a question : Is it better to invoke a class from another class (within the same module) or is it better to send an instantiated object as a parameter to the consuming class ? Look at this sample :
http://dpaste.com/1T9NAGA
Which option is better : Option 1 (calling do_now) or Option 2 (calling do_now_obj) ?
 
@WhirlMind depends. Though there is yet another pattern that is good for unittesting and subclassing and such:
class Doer:
    messages = Msg
    def do_now(self):
          self.messages.sorry
 
@vaultah that even got an upvote? :D
 
6:41 PM
Thought there is always a third one, LoL. Thank you. I would love that too. Is a kind of cross-mentioning of classes such as this, frowned upon, for some reason. ? By testing, did you mean, not good for production ? I intend to use such a pattern in production, that was just a sample. Although the final one is only a small piece of script, is that third option of yours a "best practice" ?
 
I mean it makes unittests easy to write
the pattern I mention is used extensively by the Pyramid framework
 
@Antti : Okay, Thank you. Will go with that.
 
Okay, sorry for bugging again, but why doesn't timedelta have attribute hours? Am I calling it in the wrong way?
My variable is not named timedelta, but it's time2-time1, both instances of datetime

I tried .hours,.hour,.datetime.hour. no results at all.

Now that I've looked at python documentation, it seems timedelta's attributes are days, seconds and microseconds
Do I have to do the math then?
I found a SO thread, I'm looking at it right now, sorry!
 
@Meaty doesn't, because it is plain stupid
 
True, this is the first time I've stumbled across something in python that doesn't make any sense!
I hope this will be the last time too...
 
6:54 PM
Teach noobs to import and use the full path.
 
Well, I would do that, but in codecademy they said it's not good idea as I could make a conflict if there were more methods of the same name from different modules
I hope you understand what I'm trying to say
 
7:10 PM
besides this freeware accdb-mdb-explorer.en.softonic.com/mac, is there a programatic solution to loop through a list of mdb files and convert them to csv files? each mdb has a single table.
 
7:21 PM
@jsc123 : Do you want a ready-made tool or can I give a series of steps ?
@jsc123 : Option 1 : If you have Microsoft SQL Server, do a sample DTS package for one file. Instead of running, save as VB module .bas files. Remove hard-coded references to the paths, database etc. Make a generic package. Get a list of mdb files with paths. Loop through them and call the DTS package exporting one at a time to SQL Server. Then export all tables from SQL Server to CSV.
@jsc123 : Option 2 : Assuming you have a list of path+filenames of mdb files, use a tool such as TinyTask to simulate the conversion of 1 mdb file to CSV, including the picking of the path of the mdb file from, say, Excel. Put TinyTask on a loop, picking up the next mdb file from Excel (include this step also in the loop). I have tried such stuff to online-convert loads of PDFs to html files.
 
7:47 PM
@Meaty import and use the full path, and you won't have any name conflicts.
 
Ok, thanks!
By the way, I think I have finally figured out a way to make a function which nicely defines the difference between two datetime objects and returns hours, minutes and seconds! :)
I simply convert them to integer by using object.hour*3600+object.minute*60+object.second
later I subtract them and convert them back with divmod
beautiful!
 
8:04 PM
Silly that that isn't already implemented in the middle, kinda the point of having convenient modules like that
 
true..:)
is there any place I can share the code, maybe making it useful for the community and newbies like me?
 
Is it true that the answer here can cause the problems described in the comments? stackoverflow.com/a/18866140/4230591
 
8:24 PM
Hi. I have a string s = "ababaca".

I'm trying to find all patterns length 5 that have 'a' at the start and 'a' at the end. When I use this pattern "a.{3}a" it only matches ababa and not abaca.

Can anyone explain why?
 
are you using findall
what function are you using
 
findall.
 
30
A: How to find overlapping matches with a regexp?

Otto Allmendingerfindall doesn't yield overlapping matches by default. This expression does however: >>> re.findall(r'(?=(\w\w))', 'hello') ['he', 'el', 'll', 'lo'] Here (?=...) is a lookahead assertion: (?=...) Matches if ... matches next, but doesn’t consume any of the string. This is called a loo...

 
@WasifHyder re.findall(r'(?=(a.{3}a))', 'ababaca')
 
In [24]: re.findall(r"(?=(a.{3}a))", "ababaca")
Out[24]: ['ababa', 'abaca']
 
8:32 PM
Oooh... Thank you!
I had tried the look-ahead assertion as well, but only tried so for (.{3,5})
Thanks so much!
 
8:57 PM
Also, if I want to match patterns of all lengths. For example a.{1}a, a.{2}a, a.{3}a do I need to do it in 3 different passes, or is it possible to do so in one?
 
 
1 hour later…
9:57 PM
In this meta post a user has voiced a concern that the bounty they started may be awarded unfairly. Here's their SO question, can sopython community review it and/or even provide (better) answers?
 
What is the difference between these two variables
class MyClass:
    myvar = 1337
    def __init__(self):
        self.myvar = 1337
 
class variable vs instance variable
 
how do I make private variables?
 
10:15 PM
@vaultah I'd seen that previously and thought I might have a go at it. However, it looks like the OP installation has got into a mess, probably needs some interaction to debug which the meta post now indicates they can't do.
 
I want to make my python script an executable file so that users without python can use the software. Is there any better way than py2exe you would recommend?
 
@afonsomatos Indicate hands off by prefixing with an _.
 
10:36 PM
@PeterKowalski I have no idea what the difference between them is, but there's also pyinstaller and cx_freeze
I don't use windows, so I can't recommend one over another
 
Thank you @davidism
 
00:00 - 17:0017:00 - 23:00

« first day (1708 days earlier)      last day (3239 days later) »