« first day (3336 days earlier)      last day (1835 days later) » 

15:01
Thinking about combining my AoC repos into a single repo... Google tells me it's not too hard.
Browsing through the wiki, it looks like most of us have separate repos for each year, but I see one or two mega-repos. So the idea is not unheard of.
"Not too hard" by git's standards means "the SO question asking how to do this has five answers each with 50+ points, and they all suggest something different, and there's no obvious guidance about which one does exactly what you want"
I probably couldn't be bothered to find the right way to do it.
This is the polar opposite of the DenverCoder9 scenario
I'd just pull them all and copy them all into a new repo
I mean... That's not off the table. My file history is not exactly rich and complex.
It's basically all just "solved day 11 part 2"
Besides, you could keep each year separate and just copy each new year into the megarepo and the end of the event
15:12
@Kevin top voted one seems reasonable at a glance
The only thing I'd really miss is the datetime of each commit. It's fun to know how long after the 11th it took for me to do day 11.
sounds like a job for cherry pick.. but I'd have no idea how to fix file paths, since those are part of the diff
@Kevin just use git submodules. Nothing is easier™.
woah, the first solution that recommended cherry pick was the 10th. I think I'll reconsider.
@AndrasDeak The top voted answer is usually the best one... Except sometimes for eight year old questions where it only retains its position thanks to momentum, and there are comments saying "as of 2011 this is insecure, it will erase your hard drive and kick your dog"
below that comment are 99 comments saying "this works great, as far as I can tell!"
15:17
@Kevin yeah, but I also glanced at the comments
I don't see any skulls with crossbones
Yeah, I don't think this particular post is a dog kicker.
copying repos to tmp directories before drastic steps should be part of your workflow ayway ;D
@Kevin I hope not... not sure I'd be happy with that :p
print("Name: {} Bayt: {}".format(a, *b))
@variable I don't think that's what it's saying. The child class' method can call the parent class' method without having a reference to either class object, thanks to zero argument super().
15:20
list unpacking inside format string, return only the first element !
it returns all, but you only print the first.
you have two placeholders, which are filled by a and b[0]
ops got it
so i need to do {}{}{}
depends on how many items there are in b
in case if the len of items is different, what is the proper way to unpack?
don't unpack at all. format the sequence.
print("Name: {} Bayt: {}".format(a, ','.join(b)))
15:24
Or, hmm, the next section specifically recommends doing BaseClassName.methodname(self, arguments) in order to invoke parent class behavior. So I guess that is what the author means.
Very very strange that they don't even mention super().
thank you @MisterMiyagi
@αԋɱҽԃαмєяιcαη If b contains non-str values they'll have to be str()
Is there a way to efficiently compute an array result in terms of arrays array and indices such that result[i1, i2, i3, ..., j] = array[i1, i2, i3, ..., indices[i1, i2, i3, ...], j]? I tried playing around with np.take and np.take_along_axis but can't get it quite right.
That is, indices selects from the second-to-last dimension of array.
Hahaha... how come I've only just noticed that twitter.com/eviloverflow exists? :p
15:35
Style poll: when accessing class-level attributes within an instance method, do you use the class object, or self?
#style 1
class Fred:
    x = 1
    def f(self):
        print(Fred.x)

#style 2
class Barney:
    y = 2
    def g(self):
        print(self.y)
well... what if you have both? :)
Obviously there are a number of corner cases where the behavior of these aren't identical, but let's say your project currently doesn't run into any of those corners.
I'd go for style 1 to make it clear that's what I meant
e.g. you're not inheriting from either class, Barney instances never set an instance level attribute named y, etc etc
15:38
Fred.y or type(self).y
I usually employ style #1 although I get a twinge of annoyance that the class' name appears in the class' body. It's the faintest wisp of a code smell
accessing class attributes via instances has caused all kinds of evil for me ./
I would also go with 1. Makes it clear when reading the code that it's a class attribute
@Kevin use __class__.y
Seems reasonable.
I'm not incredibly fond of using dunder names outside of dunder method implementations, but sometimes they're purpose-built for something else. e.g. if __name__ == "__main__":
15:44
Could get even more fun with inheritance :)
"fun" is the best description for using __class__
Hmm, is __class__ the one that gets injected into method scopes via dark interpreter magicks? Sprinkle holy water on keyboard before using.
stackoverflow.com/q/57903339/1709587 looks like a good question to me that sadly got downvoted and then Roombaed. It's asking something pretty fundamental about a standard library module, but is not a duplicate and is not answered in the official docs (despite being of vital importance to many potential users of the module!). Anyone here inclined to cast an undelete vote? (And perhaps to answer, if they know the answer - right now I'd like to know!)
Page not found
My only qualm about that question is that the answer may vary between Python implementations. Maybe CPython shelves are O(1) and Pypy's are O(N!)
15:48
@MarkAmery hey
Sorry @variable - it's deleted, so currently 10k+ only
@Mark umm... doesn't it somewhat depend on the underlying engine that shelve uses? I haven't used it in a while, but it can either effectively be an on disk pickle or something like bsddb - which will differ a fair bit
Hey @AndrasDeak :)
Maybe it would be answerable if it was edited to specify that it's asking about CPython in particular? idk
15:50
@Kevin and @JonClements Maybe! If so, noting the answer for CPython and also that it's not guaranteed in other implementations would probably be useful. As would any answers by anyone else who wants to provide implementation-specific answers, I guess - it's not like there are so many Python implementations that we can't cover them all.
(Really, it should be guaranteed in the docs to be O(1), and any implementations out there that aren't should be fixed, because it just needlessly cripples the usefulness of the whole module if it isn't O(1). But that's just my opinion of what should be the case; I don't know what currently is.)
@AndrasDeak Good catch, looks like it
Well, I've voted, but I'll be unsurprised if it ends up closed again
It was never closed, it got roombaed as tumbleweed
a comment or something could have prevented it
Ah, Ok. I'll be unsurprised if it ends up closed for the first time.
15:53
OK, the answer doesn't seem trivial to google
undeleted now
ahh... think I've found the bug... bbiab
here is the module's source. As Jon indicated, there are multiple underlying engines.
I'm curious what BsdDbShelf is doing there, since bsddb doesn't exist in 3.X (I think?)
lol. Backwards compatibility?
Perhaps, or they just forgot to remove it.
docs.python.org/3/library/dbm.html describes its dbm.dumb module as "slow", which is not a good sign for our non-unix users
But I suppose a method can be both slow and O(1).
Ah! Foiled by 2.7 again!
16:04
I'm going to speculate for now that it's O(1) and go ahead and use it for my current purpose (where being fast is more a nice-to-have than a strict necessity), then swing back around and see if I can improve the module and/or its docs when I've got some free time. Would be fun to get my first contributions into CPython and it's starting to smell like there might be an opportunity to do so here. :)
And at the very least, I can try to provide an answer to that question
Need to use u'\\\\?\\UNC\\' to prepend to long filepaths, rather than just '\\\\?\\'
>>> import shelve
>>> with shelve.open("data"):
...     pass
...
>>> import dbm
>>> dbm.whichdb("data")
'dbm.dumb'
Ah heck :-(
the gnu dbm manual I found makes no references or even guarantees about space/time complexity. So it's likely either eyeballing on "dbm is hash-bucked architecture which is amortised O(1) for this and that" or digging through source code.
@MarkAmery guess if push comes to shove you can always try measuring its performance
Ah, docs.python.org/3/library/shelve.html#shelve.BsdDbShelf indicates that BsdDbShelf is still usable, but you have to install the third party bsddb module first.
16:08
the elusive builtinish module
A bit odd, but I guess it's not the only first-party class with third-party dependencies. cough tkinter cough
Ok let's be fair. Call tkinter's tcl dependency "second party" since Python's installer asks if you want it.
16:42
Oh python, thou are a cruel master.
just switch to 3.7
Are longpaths properly suppported
Is that a windows thing?
I'm not familiar with the term
16:43
something something Joliet extensions?
google suggests it means "a path with more than 260 characters, which Windows may reject because it's too long"
Indeed.
The standard solution seems to be prepending u'\\\\?\\' to the filepath, and that works almost always.
640 kB 260 characters ought to be enough for anybody
uh huh
Anyway, shutil.copytree() is prepending u'\\\\\\\\?\\\\UNC\\\\' in front of my filepath that already has u'\\\\?\\' prepended to it.
Hence it doesn't work, and I cry.
>>> os.mkdir("x"*10)
>>> os.mkdir("x"*400)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'xxx<snip>xxx'
So even 3.8 doesn't like very long names.
16:47
OSError: [Errno 36] File name too long: ...
that's my linux ^
The funny thing is, it works when I run it in my console:
>>> diri = u'\\\\?\\G:\\egs_automation\\raw\\S1A_IW_OCN__2SDH_20191125T103151_20191125T103219_030066_036F0E_FB9A'
>>> diro = u'\\\\?\\G:\\egs_automation\\work\\NB_Magaguadavic_S1A_20191125_103151_RiverIceBreakupClassification\\S1A_IW_OCN__2SDH_20191125T103151_20191125T103219_030066_036F0E_FB9A'
>>> shutil.copytree(diri, diro)
>>>
so what doesn't work?
but not when I run it in the middle of the whole script
Hmm, initially I thought that it was just each segment that was limited to 260, but now it seems like the full path has to fall under the limit.
shutil.copytree() throws an exception.
Which I'll copy PART of
16:50
@Kevin yeah, that's a thing
>>> os.mkdir("x"*100)
>>> os.chdir("x"*100)
>>> os.mkdir("x"*100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [WinError 206] The filename or extension is too long
with open('result.txt' 'a')
@KieranMoynihan I would expect the same inputs to behave the same way. Are you sure the middle of your script is in the same state?
mode a will create the file if it's not and append to it?
I'm surprised that there aren't any deeply nested directories in my computer already that have fallen afoul of the limit
16:51
Unexpected error
Traceback (most recent call last):
  File "C:\Program Files\PCI Geomatics\GXL Processing Server 2018\exe/ccmeo/CCMEO_DirectoryWatcher/JPS/py/CCMEO_AutoProcessor.py", line 143, in runJob
    if self.__createWorkspace():
  File "C:\Program Files\PCI Geomatics\GXL Processing Server 2018\exe/ccmeo/CCMEO_DirectoryWatcher/JPS/py/CCMEO_AutoProcessor.py", line 284, in __createWorkspace
    shutil.copytree(file_path, os.path.join(workDir, filename))
  File "C:\Python27\ArcGISx6410.3\lib\shutil.py", line 208, in copytree
@αԋɱҽԃαмєяιcαη what did the docs and experimenting tell you?
@AndrasDeak I printed out the params passed to shutil.copytree(), and they're the same:
*** shutil.copytree(\\?\G:\egs_automation\raw\S1A_IW_OCN__2SDH_20191125T103151_20191125T103219_030066_036F0E_FB9A, \\?\G:\egs_automation\work\NB_Magaguadavic_S1A_20191125_103151_RiverIceBreakupClassification\S1A_IW_OCN__2SDH_20191125T103151_20191125T103219_030066_036F0E_FB9A)
Curious that my mkdir would fail there, though, because <my base directory>/x*100/x*100 is only 253 characters
16:52
@AndrasDeak yea found it :P
(The printout is raw text)
Maybe the segments are an extra byte apiece thanks to null terminators
Notice that somewhere in shutil.copytree() it seems to be converting the str to raw, given the number of backslashes
Time to investigate the shutil.py stack
Well, keep in mind that there is no raw type distinct from the str type
For the same reason that 0xff is an int and not a hex_int
I was just pointing out that the backslashes were added as if what was prepended was r'\\\\?\\UNC\\'
Could've been clearer probably.
16:56
Ok, I think I see what you're getting at.
And that seems weird, because you wouldn't need to escape the backslashes in r''
Any problem that involves quadruple backslashes is automatically confusing to me
Seems to be Octuple there.
I'm recoiling
@JonClements Unnoticed for a year, yikes
Well, at least it's not too likely that anyone installed je<capital I>lyfish instead of jellyfish, since that's not an easy typo to make
17:02
Probably only by copying the name, if someone maliciously posted that somewhere.
Yeah.
Or by direct link
That was the sleeper - hardly anyone would make that typo. After a year with no eyebrows raised, then the real trip was set, with a reasonable impostor that imports the other
it's an awakening for me: I usually just copy-paste the pip install on the package page, so the "it's not an easy typo to make" argument doesn't work on people like me
Too bad we can't see download statistics for the modules.
17:08
you used to be able to... and then they killed that in about 2011. I remember this, because I uploaded my first python package then for an assignment and did a live check of download stats. They killed the feature shortly thereafter :'(
Username is an anagram of 'godlier'
More cleanlier?
More godly
oops! I misread "godlier" as "doglier" and offered "godlier" as an anagram thereof
doglier is not a word, though maybe it should be
17:13
sure it is! It's a person that gets dogs to lie down
I often tell my dog I wish come back as her in my next life
it works particularly well if she comes back as you at the same time
Hmph
Shutil.py() is no more revealing.
Perhaps I'll need to actually ask a question to the general populous of SO
@KieranMoynihan There is no such thing as "converting a str to raw". Raw strings are just strings.
So they lowered closed votes to be 3 instead of 5. I'm wondering if they saw a decline in number of flagging to help justify this... in response to what AD linked
17:21
Their "rawness" comes from the interpreter's recognition of the 'r' prefix as a signal not to interpret '\' as escapes. I am careful to always refer to them as "raw string literals".
@PaulMcG I understand that, I just wasn't clear in my explanation. The string prepended to the file path should be something like '\\\\?\\UNC\\', but it ended up as '\\\\\\\\?\\\\UNC\\\\', which suggests that what was prepended was r'\\\\?\\UNC\\', rather than u'\\\\?\\UNC\\'
Which doesn't make sense, because there's no need to write r'\\\\?\\UNC\\' over r'\\?\UNC\'
Those are two different strings
I'm very aware of that.
and ru'\\?\UNC' is also allowed
17:35
Trailing single backslash won't work in raw string literal, though, so it still needs to be doubled. Perhaps the dev was trying to avoid future confusion about why one backslash was doubled but others weren't? (But I would have opted for a comment myself.)
Anyone doing Advent of Code? Today, I had gotten myself all set up with a recursive 'count all possibilities' approach when I figured out that there are only a very limited number of values that fit the 'increasing digits' criteria.
so I ditched my recursive approach (which was producing too low a value because of a bug somewhere) and hacked together a brute-force version instead.
Yeah, I went with brute force as well, because of (as you say) there being so few increasing digits
Now, I realize I'm probably going to come off as an idiot in a second, but it sure seems like I'm calling the exact same function .copytree() with the exact same parameters, from the exact same module shutil with the exact same python.exe executable, but getting different results.
And, if I'm being honest, I'm not sure how else to check what's different between the two function calls
If I print out the relevant information in my script before the function call:
        print sys.executable
        print shutil.__file__
        print 'shutil.copytree(%s, %s)' % (repr(file_path), repr(os.path.join(workDir, filename)))
        shutil.copytree(file_path, os.path.join(workDir, filename))
Giving me the outputs:
C:\Python27\ArcGISx6410.3\python.exe
C:\Python27\ArcGISx6410.3\lib\shutil.pyc
shutil.copytree(u'\\\\?\\G:\\egs_automation\\raw\\S1A_IW_OCN__2SDH_20191125T103151_20191125T103219_030066_036F0E_FB9A', u'\\\\?\\G:\\egs_automation\\work\\NB_Magaguadavic_S1A_20191125_103151_RiverIceBreakupClassification\\S1A_IW_OCN__2SDH_20191125T103151_20191125T103219_030066_036F0E_FB9A')
Unexpected error
Traceback (most recent call last):
  File "C:\Program Files\PCI Geomatics\GXL Processing Server 2018\exe/ccmeo/CCMEO_DirectoryWatcher/JPS/py/CCMEO_AutoProcessor.py", line 143, in runJob
wim
wim
@Kevin please do
17:46
And if I run it from console with the same python exec and params:
>>> print sys.executable
C:\Python27\ArcGISx6410.3\python.exe
>>> print shutil.__file__
C:\Python27\ArcGISx6410.3\lib\shutil.pyc
>>> shutil.copytree(u'\\\\?\\G:\\egs_automation\\raw\\S1A_IW_OCN__2SDH_20191125T103151_20191125T103219_030066_036F0E_FB9A', u'\\\\?\\G:\\egs_automation\\work\\NB_Magaguadavic_S1A_20191125_103151_RiverIceBreakupClassification\\S1A_IW_OCN__2SDH_20191125T103151_20191125T103219_030066_036F0E_FB9A')
>>>
How else can I check the difference between the two executions?
wim
wim
@Kevin It's not really a "style" decision. Depends whether you want to allow subclass to override, or instance attribute to shadow.
@wim What did you decide to do with the aocd Puzzle stats if only Part 1 is done?
wim
wim
@KieranMoynihan raise.
check comments @AndrasDeak stackoverflow.com/questions/59181251/… :P am friendly now ahaha
"we need to guide him". That's what he's doing. He's giving the OP constructive actionable advice.
wim
wim
17:56
@KieranMoynihan that's almost summoning ba'al, the soul-eater
@Kevin that's not friendly way . it's like ordering .
I see three "please"s there, that's as friendly as you can get
@αԋɱҽԃαмєяιcαη that's 100% noise
@wim Yes, unfortunately it's just the backslash to end all other text. And it seems to be doing a fine job of that.
To be clear about my earlier question, if I copy-paste the line I tested in cmd.exe into the script as a hard-coded replacement to the line that is throwing the error, it still runs into the same error. I have no idea why that would happen, but I imagine it means there's something different about the python instance.
18:02
@AndrasDeak alright.
Ok, I'll compromise and say that the comment looks friendly to me, but it might not look friendly to other people. My advice in that case is not to scold the commenter for being too unfriendly. Instead, write your own friendly message that coaxes the OP to write a better question.
Lead by example :-)
wim
wim
Don't answer that question
Simply answering the question doesn't feel like guidance to me because it won't teach the OP anything, other than "I don't have to improve myself because they'll answer my mediocre questions anyway"
wim
wim
See section 8. Prohibited Conduct, part I
they should not be using a scraper, I've downvoted your answer and the question
wim
wim
18:08
And that commenter was already trying to give constructive advice. Otherwise they would just edit the crap out of the question directly.
@αԋɱҽԃαмєяιcαη you also shouldn't answer crap questions. That's not guiding
@KieranMoynihan I wonder if it might be worthwhile to write a custom copytree implementation from scratch, using just os.walk and open(). Then, in principle, any errors you encounter will be more comprehensible since you wrote the code yourself.
You can even add your own custom logic to detect UNCs so they don't get doubled up, or whatever
@Kevin I just discovered that it works if I put it right at the top of the file, above any imports except shutil, so I'm on the path
Heh, I hope the path isn't too long ;)
@AndrasDeak well, for me it's a very simple topic. someone asked a question then i answered it. i will not check each single question and read the terms of service for the website. it's belong to the one who asked the question.
i don't like to lie myself. the OP can just hide the url or whatever, and at end he will take the answer and apply to his desired url.
Mm, I think you should read the terms of service, though. In my opinion, part of our due diligence as answerers is that, to the best of our knowledge, our contributions aren't being used for malicious purposes.
18:11
and regarding the comment section. yes it's might be friendly for you. but for others not. that's why there's upvote and flag option.
@αԋɱҽԃαмєяιcαη crap in SO terms
wim
wim
Don't help people to do bad things. It's common sense, really.
i don't think that downloading img is bad thing. at least for me !
Obviously there's a limit, since even a padleft function could be used for evil and we'd have no way of predicting that, but I think the limit includes checking that the target site of a scraper is OK with it
what he can do with img !
wim
wim
18:12
-146
Q: How to send 100,000 emails weekly?

xRobotHow can one send an email to 100,000 users on a weekly basis in PHP? This includes mail to subscribers using the following providers: AOL G-Mail Hotmail Yahoo It is important that all e-mail actually be delivered, to the extent that it is possible. Obviously, just sending the mail conventiona...

^ See the score of this question for precedent here
xRobot with 19.k rep and he don't know the terms of service. sound strange
wim
wim
@αԋɱҽԃαмєяιcαη Have you ever run a website? You want it to be up and available for people browsing with their browser
There are plenty of bad guys with high reputation. If anything, being a psychopath makes it easier to climb the ranks.
wim
wim
If the website is getting slammed by some script kiddy, that's annoying. Especially so when you actually have a public API for devs to use.
(I'm not thinking of anybody in particular here, just extrapolating from trends in wider society)
18:15
@Kevin well i think that SO should track this and remove the rep with warning MSG.
@αԋɱҽԃαмєяιcαη yeah right
I think mods are capable of doing that, in egregious circumstances
at least in this warning MSG, it's will be knowledge for the answer for which reason he lost rep.
@αԋɱҽԃαмєяιcαη great excuse
Hi guys
18:19
Greetings
I have a heavy google sheet which is importing data using many apis, as a result its very difficult to handle
@wim Yea that's good. but i will not keep asking each visitor to do good things. so the safety and secure is my task as a website owner.
I want to clean some data in it, how do you think I should go about it
?
@RaphX what is the data type ?
Please elaborate on "very difficult to handle"
18:22
By the phrase 'difficult to handle' I mean I can't open the google sheet and manually edit it, it hangs everytime I try to do it
There are different data types including datetime columns, full string columns and fully numeric columns, hyperlinks etc. @αԋɱҽԃαмєяιcαη
So this google sheet is executing Python code when you open it? I didn't know that was possible.
wim
wim
charitable assumption or sarcasm?
No but its using some api which is based on python code I guess, anyway thing is I want to know whether I can use python to get around this ?
@wim Charitable assumption. Excel can run arbitrary code, so Google sheets can too, maybe?
wim
wim
@JonClements who is behind eviloverflow? funny!
18:26
When you say, "its using some api which is based on python code", how can you tell? It's OK if the answer is "it's just an educated guess based on clues X Y and Z", I just want to get an idea of what led you to this train of thought.
There is an inbuilt api which is based on python and they use that api to pull data from an internal tool @Kevin
usually google sheets is sorted. so i think the issue is not in the sheet itself
Yeah I think it could be because of so many api calls
Hmm. If the api we're talking about is developers.google.com/sheets/api/guides/concepts, then it would surprise me if it was responsible for slowdown when viewing the sheet, since (AFAICT) the API isn't capable of making dynamic changes to the sheet while you're looking at it.
Much like how python's file.write can't change the contents of a file while you're looking at it in Notepad.
Certainly the API could create a file so huge that viewing it would be slow, but it wouldn't be any slower than an identical file made by hand
But anyway. If the question is "can I efficiently read/write segments of a very large Google sheet using the API?", then it seems that the answer is yes. developers.google.com/sheets/api/guides/… indicates that the API can return only the parts of the sheet that you care about.
So Google Sheets API is what I should look at @Kevin?
18:35
I think it would be worthwhile to check out, yes
Ok I will check it out
Even if I'm wrong about the dynamic updates thing, querying the data with the API instead of viewing the sheet in the browser is probably still going to be faster
I will need to update the data there, I can view it anyway using pandas or even inbuilt query formula
how do I eliminate all data points where x and y are two separate lists where y equals a certain value
If by "I will need to update the data there" you mean "I have to open the sheet in a browser if I want to edit it", I think the API can do it too. It might be harder to formalize the logic, but it's feasible probably.
18:42
crap nevermind, my X is a list but my y is a numpy array so I'm just going to convert my X to a numpy array as well
@erotavlas I'm thinking x_vals, y_vals = zip(*[(x,y) for x,y in zip(x_vals, y_vals) if y != certain_value])
Oops, I assumed they were both lists. Oh well.
lol its ok
General design tip: it's usually easier to manipulate this kind of data if you have a single list of (x,y) tuples rather than separate x and y lists.
Or, they don't need to be tuples necessarily. Any object that bundles all of the related data into one place works. Dicts, class instances...
yeah that's true
For huge data it might make sense to separate them, which might get you efficiency at the cost of a friendly interface. I don't know, I'm not a Big Data guy.
18:47
I just did this

data = np.column_stack((X, y))
I figured it out, yippee.
👍
Something in an import necessary for this particular script changes something about the way (I guess) shutil works by implementing long path support itself, but NOT ALLOWING any already formatted as long path string as inputs.
So I have to use long paths for some things, and I can't use it for others. Very nice.
Windows delenda est
Nonono
It would've been fine if not for the necessary imports overstepping the bounds of what they should've been doing.
Besides, Windows 10 now allows you to remove the 260 character limit on filepath lengths for standard use.
19:10
This AOC I'm experimenting with comparing adjacent sequence elements using [s[i-1] == s[i] for i in range(1, len(s))], rather than my usual [s[i] == s[i+1] for i in range(len(s)-1)]. The advantage of the new way is that it has one less explicit arithmetic operator. Most likely it's not any more efficient, but perhaps it saves the reader an iota of mental labor?
Tis the season for incredibly marginally useful style changes
user10984358
hey guys trying out some recursion, so can anyone tell me how I can make this a generator that is recursive? if at all that is possible, this is just a toy code, if you run the code you might understand what kind of pattern it does
user10984358
def do_that(string,start=1):
	end=len(string)
	if start>end:
		return
	for idx in range(start,end):
		t=string[:idx]+'.'+string[idx:]
		print(t)
		do_that(t,start=idx+2)

do_that('12345')
Generator, as in, a function that uses yield? If you're using 3.X, get familiar with yield from, which is a nice way of passing elements yielded from inner generators up to the original caller.
user10984358
yeah so I can use the values like an itertools.combinations object
user10984358
been looking at this stackoverflow.com/questions/38254304/…, this does it?
19:18
If I get your meaning, you want something like:
def do_that(string,start=1):
	end=len(string)
	if start>end:
		return
	for idx in range(start,end):
		t=string[:idx]+'.'+string[idx:]
		yield t
		yield from do_that(t,start=idx+2)
user10984358
the code uses (abuses) the period trick in gmail so I can generate multiple emails with periods for a single email, a bot does account creation
user10984358
so to make a recursive call I just use a yield from and do the call? thats it?
All I really did here was change the print to a yield, and put a yield from in front of the recursive call. This kind of transformation usually works if you already have a function that prints the output you want.
user10984358
if I want some kind of order then I have to change the algorithm behind this generation?
A fun exercise would be to redesign your function so it doesn't use a start parameter, only string. That transformation is less obvious, but should be educational
Hint: you probably would not end up using yield from in that case.
@TheNamesAlc Yeah.
user10984358
19:24
ahh that seems interesting, will try doing that
user10984358
can I sneak this in instead of changing the algorithm? sorted(do_that('someone'),key=lambda x:x.count('.'))
user10984358
if order is of importance
Here's my take on the one-argument approach, for your later perusal pastebin.com/ii14JinX
user10984358
almost clicked that
@TheNamesAlc Sure, that works. But it defeats one of the selling points of generators, which is their memory efficiency. To call sorted, you have to store every element in memory at once.
Not a big deal if your input string is five characters long, but once you get to like 20, you're looking at a list with a million elements.
user10984358
19:32
I didnt do the math enough to realize how much it would generate, what is this type of math called? I suck bad at recursion I just changed the idx and it worked
Generating all values in order of number of dots is pretty tricky... It's not immediately obvious to me how you could do it efficiently. I do think it's possible though.
@Kevin Welp, I found out what the something in the imports was doing to mess with shutil. It was changing the behavior of open() via __builtin__.open = wrap_name_mode_buffering(open)
Go about 4 functions down and it doesn't check if I've already formatted for long paths, so it gives up
@TheNamesAlc I don't know if there's a name for this kind of analysis, exactly. I just reasoned: for every pair of characters in the input, you can choose to add a dot, or don't. So there are len(input)-1 independent choices you can make, meaning there are 2 ^ (len(input)-1) possible outputs
This is the case regardless of whether you implement the solution with recursion or not
user10984358
ahh, when I was trying with strings like "abc" I was half convinced my code worked, but when I did '1'*20 it froze and I knew it was working, an iterative approach is possible? I just saw and my gut feeling knew enough to find that this is recursive
Yes, an iterative approach is possible. Basically, you iterate over the n-fold cartesian product of (False, True), and in each iteration you use one bool for each input character to decide whether to insert a dot.
user10984358
19:39
n = len(input-1) ?
Or, if "N-fold cartesian product of (False, True)" is a baffling concept, think of it as iterating over all binary sequences that are N digits long
@TheNamesAlc Yeah.
user10984358
like a truth table?
You don't even need itertools.product to do the cartesian product, necessarily... You could iterate over for x in range(2**n) and inspect x's binary digits via bin(x) or perhaps some bitwise arithmetic
@TheNamesAlc Pretty much.
user10984358
this might be in some order I believe
Yeah. But not in the "number of bits" order you're aiming for
user10984358
19:43
once my bot is done, I will try an iterative generator
user10984358
also is doing account creation using selenium qualifies as a bot? or it has to do some uber cool things
There may or may not be a ready made algorithm for iterating over [0, 2^n] in "bit count" order, floating somewhere around the Internet
@TheNamesAlc That's subjective, but I say it qualifies.

« first day (3336 days earlier)      last day (1835 days later) »