« first day (3681 days earlier)      last day (1491 days later) » 
00:00 - 20:0020:00 - 22:00

00:40
First release of the Array API Standard (next step in trying to standardise an array API for python
 
7 hours later…
07:58
cbg
a = [[1, 2, 3], [1, 2, 3]]

new = list(map(lambda x: x[1]*2, a))

print(new)

# current output > [4,4]

# Expected [[1, 4, 3], [1, 4, 3]]
08:13
@αԋɱҽԃαмєяιcαη - are you still puzzled by your results?
@PaulMcG, yes. i would like to use map instead of list comprehension if that's possible.
Ok - a is a list of lists. Your current use of map is equivalent to [x[1]**2 for x in a]. So you are getting a list containing [a[0][1]**2, a[1][1]**2] -> [4, 4]
@αԋɱҽԃαмєяιcαη any reason why?
I have a map based solution, will wait to see how it goes, cbg btw
@JonClements actually i would like to test it on BigQuery to check difference of speed between it and list comprehension
08:19
If you have a list of lists, and you want to perform some operation on each item in each list, you will need a map of maps. That is, a nested call to map.
@PaulMcG something like lambda x,y,z: x,y*2,z ? if that's the case, how about if the list is holding thousand of elements where i know the direct index
A list containing some number of 1000-element lists?
list of lists, where each list containing like 1k of elements.
You might be looking for lambda x: [*x[:i], x[i] * 2, *x[i+1:]]
with i=i in your case
I think i=1 in his case
08:25
lambda x:x[:1]+[x[1]*2]+x[2:] is what I had
so we are indexing it then plus 1 to pickup the element
coughs innocently
@python_learner ooh, you are right. got carried away with unpacking.
I thought your '*' notation version was equivalent (and possibly faster)
idk if unpacking or concat is faster
@αԋɱҽԃαмєяιcαη - do you see how to apply these lambdas to your list of lists using map? (You'll need a nested call, a map of maps)
@PaulMcG naively, I expect that unpacking is slower since it goes through the generic iteration interface. Concatenation can rely on having concrete lists.
Oh wait, I was wrong - just a single call to map using either of those lambdas. I had in mind that you wanted x*2 for every element in each list, but you just want the i'th element. So replacing your posted lambda with either MM's or p_l's lambda will work.
%timeit [*values, *values]
18.7 µs ± 141 ns per loop
%timeit values + values
14.9 µs ± 385 ns per loop
closer than I expected. 4096 elements
@PaulMcG no problem. i got it from first comment, i thought you are just advising in case if i will deal with nested lists
I should really learn to have timeit in my muscle memory, I refer for once and I forget the next time :/
08:37
>>> timeit("map(fn, a)", "fn=lambda x: [*x[:1], x[1]*2, *x[2:]]; a=[1,2,]+[3]*1000")
0.43740129307843745
>>> timeit("map(fn, a)", "fn=lambda x: x[:1] + [x[1]*2] + x[2:]; a=[1,2,]+[3]*1000")
0.44535748893395066
Not at a computer but I suspect casting to a numpy array and doing it that way may be faster, even if slightly unintuitive
@PaulMcG good old "it doesn't matter in practice" ^^
Paul just curious you have a slow PC? :p
0.16845338200005244 in my test for unpacking
RaspberryPi
ahh I read someone using a Rpi in chat, missed seeing the name
08:41
JonClements first posted about it.
will read on that, how did the interview go? you interview people or you were interviewed ?
What is the right term in order to make research on url parameter decompositions?
I would like to make some text mining based on urls. I need to split them into words.
I assume that delimeters are ?, -, _ ,.,/,&. But this is manual approach really.
There should be much more professional library or approach ? Currently looking into urlparse
but it has not got this division part.
@python_learner timeit is really handy in IPython. MisterMiyagi endorses IPython. Swap your REPL for IPython today! Disclaimer: Following existentialist advice may cause dizziness, disorientation, and loss of good taste.
I was being interviewed. If it went well, I would have posted.
Probably they will downvote if I ask it on stackoverflow question side. So I try chat side, I hope you guys have some idea about that ? Thanks in advance
08:47
@ozturkib You should use urlsplit instead of urlparse.
Either way, both will handle all URL delimiters – things like -, _, . are not delimiters as far as URL is concerned.
there is always a next time :), IPython has also been on my radar for a while
Thought I had a typo. Check my work?
>>> timeit("[x[:1] + [x[1]*2] + x[2:] for x in a]", "a=[[1,2,]+[3]*1000]*2")
36.493928979034536
>>> timeit("[[*x[:1], x[1]*2, *x[2:]] for x in a]", "a=[[1,2,]+[3]*1000]*2")
35.32019128394313
>>> timeit("map(fn, a)", "fn=lambda x: x[:1] + [x[1]*2] + x[2:]; a=[[1,2,]+[3]*1000]*2")
0.431134590995498
>>> timeit("map(fn, a)", "fn=lambda x: [*x[:1], x[1]*2, x[2:]]; a=[[1,2,]+[3]*1000]*2")
0.4459305020282045
From my point of view, they should be delimeters.
because I would like to do text mining on those extracted words.
list comps vs. lambda - the disparity is surprising
Well, then you have to do so yourself.
08:51
it means I have to implement splitting side on my own for this process ?
However, I assume that this reasonable approach for text mining so there should be something ?
@PaulMcG erm... map versus list. nudge nudge
user14463336
hi
14.262498320000304,14.248109203999775,0.1648312590000387,0.163932806000048 respectively @PaulMcG
example: /26031_abone-veri-tabanları?aaaa-bbb.ccc.html
example output : [26031, abone, veri, tabanları, aaaa, bbb, ccc]
@ozturkib This seems like a decent question, if posed as "I'm trying to split url parts into separate words, I tried X expecting "Y" but got "Z" instead".
08:53
@ozturkib It might be reasonable for text mining. It is not reasonable for URLs. If you want to treat your URLs as text, of course you can do that.
am I missing something or that actually shows map is faster? I thought comps were faster
I know this is silly example but i mean i would like to look into url sub words and do not want to use manual approach like split them, because I assume that there are more handy way.
@python_learner you might want to print the result of map(bool, [1, 2, 3]). ;)
@MisterMiyagi exactly it is not handy for url side, I definitely agree with you.
ahh never mind, its lazy, thought there was a list call there
08:56
I still have the nested list stuck in my head - I had in mind that the lambda fn was being called for each element in each sublist, but it's only being called once per list. Generally function calls are poor performers in Python, so I thought n*1000 calls would be slower than iterating. But it is just n calls.
Is there a name for the list of "?", "+", "-", "=", "_", ".", "/", "&" inside url composition or decomposition ?
Hi back at you @SxolarBit - but can you not post blocks of nonsense though please?
The list can be extended of course, this is what i observe currently
I am entirely sure there is huge literature which I am currently not aware. Because focused web crawler methods are already handling this kinda things.
@SxolarBit straight after you said "hi" - you managed to post two messages consisting of entirely W's.... let's not repeat that :)
If those delimiters are in a url, I think they will be url quote'ed.
>>> urllib.parse.quote("?+-=_./&")
'%3F%2B-%3D_./%26'
09:03
@PaulMcG Can you rephrase what you say because I am not entirely sure about that. Sorry for that.
I do not have fixed set of urls, I would like to make an approach which is suitable for entire urls and then test it.
What I'm saying is, I don't think you will find urls that have '?' or '&'s in them as word delimiters, since they are used as url notation.
@ozturkib The symbols which are delimiters in URL can either appear as-is when they are actually delimiters, or escaped when they are part of the "content" of the URL.
what i observe cannot be a novel thing, it must be implemented before as I said at least in the area of focused web crawler.
As @PaulMG's code shows, -, _, / and . are not URL delimiters – there is no escape for them.
yes they are no delimeters I know.
But once I am reading many of urls, they are used as word seperation by people.
09:07
It's not rocket surgery. Use urllib.parse to extract the parts, urllib.parse.unquote on the parts to get the actual words, then extract the words.
yes but can be better approach which is already tested. Of course i can do it easily with split
But similar to my observation might be tested or implemented before so I want to see this literature. This is the reason I came here.
for instance i forgot to add % into the list once I was writing it, so this one can might also be added etc.
Basically you are saying there is not any approach like that from the url composition or decomposition side ?
urlparse/urlsplit will already take care of % for you
It's not really clear what you want that is not already in urllib
I'm saying that, from what I can tell from your posts so far, it should be < 10 lines of Python code (using urllib.parse methods), so not likely to be a library.
Alright then @Pau
Alright then @PaulMcG
thanks for your comments
@MisterMiyagi
thanks a lot
@MisterMiyagi "there is no escape for them" - they suffer a grim fate
09:17
gruesome
certainly, every emoticon made of them looks like Texas Chainsaw Massacre: URL split
/._-
 
2 hours later…
11:11
print(datetime.now().strftime("%m/%d/%Y %-I:%M:%S"))
ValueError: Invalid format string
is %-I is not readable for Windows
%-I = Hour (12-hour clock) as a decimal number.
> %-I Hour (12-hour clock) as a decimal number. (Platform specific)
I don't think %-I is valid, I think you want just %I
%I is zero padded
Since %H is 24 hour time
11:13
So yeah, it might be platform specific
Hour (12-hour clock) as a decimal number. (Platform specific) (from strftime.org)
So as you suspected
Thanks for confirming
I've never used the '-' variants on these placeholders, interesting.
11:15
i used it in date format too and it was working only in Unix
They should update with Platform Specific
@αԋɱҽԃαмєяιcαη oh no, unofficial information on the internet is wrong
TIL... how threading.local actually works and that info is only in the docstring of _threading_local module and not on the docs.python.org :D
@AndrasDeak is strftime.org official ?
@αԋɱҽԃαмєяιcαη nope. But a lot more reliable than some random coding site
i see. thank you
11:20
Typically you look for reliable information in the official documentation. If something's missing you start looking for reliable third-party sources. Hint: the vast, vast majority of third-party resources is crap.
11:31
@AnttiHaapala The cute part is that _threading_local.__doc__ starts with what is basically a "don't use this" notice.
@αԋɱҽԃαмєяιcαη I don't think that is valid.
Never used subclassing with threading.local because it wasn't clear to me which behaviour is for the pure-Python implementation and which works in general.
@MisterMiyagi indeed :'D
but that is how you should use it for factories and expensive initializations and such
instead of that horrible "if not getattr then setattr..."
hurries off to check their usage of threading.local
Oops...
12:03
I'm rather fond of the popular "For Want of a Nail" in Javaland
EquestrianDoctor.getLocalInstance().getHorseDispatcher().shoot(); :P
The question is, do you shoot the Horse, the HorseDispatcher, or the Doctor?
The language designers?
 
1 hour later…
13:24
Cbg Pears.
I hope you all had a good week.
I still hear "1 hour later..." in the voice of the SpongeBob narrator.
Is it okay to ask a stupid pandas question here?
13:42
You are welcome to ask pandas questions here; we have some rules about questions such as posting code off-site it it's quite a long block :)
hi ignore my noob status on python, i need to run a command python -m youtube_dl_server but i cant as i have pytthon 3 how do i get around it, python3 doesnt like the command
im using ubunto 2020
@n4zg Define "doesn't like the command". ModuleNotFoundError? No module named ... ?
did you install youtube_dl_server?
the package page lists it as compatible with python3
youtube-dl is currently under DMCA on github although I wouldn't expect that to leak out into pypi
13:48
i was provided the source from a unity plugin
and did you install that source?
Not long code, obviously. But too simple for a real question on SO. I have seen so many tutorials and documentations but none addressed this.
python -m youtube_dl_server
-bash: python: command not found
Well, that doesn't have anything to do with youtube_dl_server
when i do python3
raise ValueError("cannot have a multithreaded and multi process server.")
ValueError: cannot have a multithreaded and multi process server.
13:54
as per python.org/dev/peps/pep-0394 "python" is replaced by "python3"
Assume df with columns "A", "B", "C" and rows indexed as "X", "Y", "Z". I can set values as df.iloc[1,0] = True or df.loc["Y", "A"] = True.
But what if I want to set the value for 1 and "A"? df["A"].iloc[1] = True works but gives the infamous SettingWithCopyWarning. So does every other approach that works. Is there no legit way to do this?
is this compatibility error
@n4zg please consult the documentation of the package on how to tell it whether to use threads or processes.
can i put the stacktrace in here
only if it is reasonably short. use a code paste service otherwise.
13:57
@Mr.T bane of my life. In all likelihood it can be ignored. I have a meeting now but I'll see if there's a way to avoid it
@n4zg github.com/jaimeMF/youtube-dl-api-server/pull/65 also reports the error cannot have a multithreaded and multi process server.. Apparently they fixed it by adding threaded=False to server.py.
16 lines
16 lines is fine
python3 -m youtube_dl_server
* Serving Flask app "youtube_dl_server.app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/root/aloserver/youtube_dl_server/__main__.py", line 6, in <module>
Oh hey, it's the same stack trace as the issue I linked. That's encouraging -- it implies that the fix they suggest will work for you too
13:59
@Mr.T Actually, this doesn't repro the issue
import pandas as pd


df = pd.DataFrame({'A': [1, 2, 3],
                   'B': [4, 5, 6]})

df['A'].iloc[1] = 7
Unless I silenced that warning one grumpy evening and forgot about it :P
If you can't figure out how to modify the files of a package, maybe you can just do python3 -m youtube_dl_server --number_processes=1. Not totally sure that will work though.
@roganjosh I'm pretty sure I haven't silenced any pandas warnings, and that code doesn't give me warnings either
didnt work
morning cabbages folks!
Which didn't work? Modifying server.py? --number_processes=1? Both?
I don't typically go political around these parts, but this song is way too catchy
14:06
--number_processes=1
what shoudl in server.py
add
Change the last line to app.run(args.host, args.port, processes=args.number_processes, threaded=False)
@roganjosh I thought I am even more stupid than I am. Your version doesn't raise the Warning. Minimal example:
n=3
b = np.random.choice(list("abc"), size=3)
val=np.random.randint(0, 20, n)
df = pd.DataFrame({"A": b, "B": val}, index=list("XYZ"))

df["A"].iloc[1] = True
that started the server - thank you very much
Cool 👍
any idea how i can test it
14:11
Apparently you need to send a REST request to the computer running the server. The parameters are described at youtube-dl-api-server.readthedocs.io/en/latest/api.html
:~/aloserver# python3 -m youtube_dl_server
* Serving Flask app "youtube_dl_server.app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://localhost:9191/ (Press CTRL+C to quit)
how to link to external call
What kind of external call?
Another one silly question from me: if I have a ascii string, is there any way to compress it but as output get another ascii string, not bytes.
@Mr.T The issue seems to be modifying dtype: object series.
@VictorVosMottor Define "compress". Converting from string to bytes almost always makes the string longer, so I'm curious what string-to-bytes compression you're using.
14:17
@VictorVosMottor It's not possible to compress arbitrary data from one format into the same format.
@Kevin zlib.compress
That might do it :-)
>>> zlib.compress(b'hello world'*100)
b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\xc9\x18e\x8e2G\x99\xa3Lr\x99\x00\x9b+\xb4\x00'
@Kevin in unity i need to provide a url
@VictorVosMottor and what output would you want instead? Be specific.
14:19
@AndrasDeak only printable characters: ascii, maybe utf. Is there any such function?
@n4zg Probably something like localhost/api/info
ok i am trying that now
@VictorVosMottor and which characters? What are you going to do with this text later?
@AndrasDeak just interested
14:20
U-huh
@VictorVosMottor there's always def asciify(inp): return 'potato'
@VictorVosMottor Consider that you are asking how to compress ASCII into ASCII. If that were possible, you could infinitely repeat compressing data until there is only one bit left.
@MisterMiyagi no, they aren't even asking that. They don't know what they're asking, apparently.
As far as I can tell we're at "How can I paint my unicorn's hooves blue?" "Which subspecies of unicorn are we talking about?" "Oh, I don't have a unicorn, just curious"
Well, it's the content of their request. "I have a ascii string, [...] compress it [...] as output get another ascii string". I assume it's not what was intended, but it's what it amounts to.
@Victor base64.b64encode is a fairly typical way of turning a bytes into a human-readable bytes. Of course, the result is usually longer than the source, so you're counteracting your compression a bit.
@MisterMiyagi nothing was said about the length of the resulting ascii. For all we know the expected result could be 'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\xc9\x18e\x8e2G\x99\xa3Lr\x99\x00\x9b+\xb4\x00'
14:23
@AndrasDeak Oh, in that case... go, potato!
@AndrasDeak That's not compression, is it?
@MisterMiyagi with a loose definition of "compress" perhaps
@MisterMiyagi I don't understand your comment. What is the difference between the way @roganjosh created the df and mine? Why would pandas consider one version okay, but not the other? For me, they look similar (but then again pandas and I have never been mates).
@AndrasDeak I got a string X characters long. I want to compress it to the other string Y characters where Y < X and I want that other string be able to be decoded back to the original string and be ascii as the original string.
def compress(data):
    return ''.join(c*2 for c in data)
@VictorVosMottor thank you. No, not possible.
14:24
ok
@MisterMiyagi What does this have to do with it?
Just kidding? ;)
How firm are you on the Y < X requirement? Because any practical compression algorithm you can find anywhere will in some cases return a string with Y > X.
It's an unbreakable principle of the mathematics underlying the concept, alas
@Kevin I mean if the original string is enough long. I know sometimes it may be Y > X.
@VictorVosMottor 'twas a reply to Andras, but pings cannot be compressed into code blocks :(
14:28
@MisterMiyagi ok
It sounds like you're pretty happy with the compression that zlib delivers, so I think we can set aside the "compression" part of the question entirely
@VictorVosMottor Consider that this is very much possible if your data is not perfectly uniform, i.e. if it has some known, reliable features.
It seems like what you're after right now is "a way to turn the bytes that zlib produces into a string, composed only of ascii characters; and a way to turn it back later"
ok, ok, ok. I'm "un-asking" my question and going to read about it. ;)
adding [closed] as it needs more details or clarity myself.
Have a nice day ;)
I suggested base64 as a way of turning a bytes into an ascii-only bytes, and converting from bytes to string and back is as easy as calling their encode() and decode() methods
So basically all the pieces are there, just play around with them for a bit
14:33
Alternative: Just live with bytes. They exist for a reason.
that's exactly what Big Bytes wants you to think
3
bytes are very good and I think everyone should use them more
(this message sponsored by Citizens For Bytes)
14:53
phew, this was difficult
>>> len(s)
1100

>>> set(s) <= set(string.ascii_letters + string.digits)
True

>>> len(base64.b64encode(zlib.compress(s.encode())).decode())
1140
apparently zlib is really good at compressing text
Ok so I have a quick question, I have no experience with this type of python so as much help as you can give me would be great. How would I use a python script to wait for a word to be said and then make a message pop up on my screen. (I am using a mac if that is any help)
@roganjosh Now the absolute minimal example to reproduce the Warning, removing all unnecessary functions:
import pandas as pd

a = ["x", "y", "z"]
b = [1, 2, 3]
#Warning
df = pd.DataFrame({"A": a, "B": b})
#No Warning
#df = pd.DataFrame({"A": a, "B": a})

df["A"].iloc[1] = True
Based on a bit of testing, zlib-and-b64 compresses lorem ipsum by about half, and randomly selected letters and digits by about nothing
Which makes sense because text resembling an actual language has less entropy than noise
Sorry, just got out of my meeting @Mr.T . I'm confused, I'll have to think about that a bit
Does anyone know where I would start to accomplish voice recognition for a keyword?
15:03
@roganjosh No worries, I will be away for a while now. Thank you for taking an interest in it. At the end of the day, I can probably just ignore the warning but I am really confused by this behaviour.
15:44
Every time I come to use pandas.where() I have to stop and think. Surely it's not just me that thinks it's a bit bonkers to select rows where the condition is False?
Or it's my own mental wiring that's bonkers. That's a distinct possibility, too
16:01
> The signature for DataFrame.where() differs from numpy.where(). Roughly df1.where(m, df2) is equivalent to np.where(m, df1, df2).
The behaviour seems backward for me too, for what it's worth. I can see why it does what it does, but I wouldn't have named it where of all things
or I would've made it pandas.where and match numpy's signature
Yeah, even just a .wherenot would help
It's mentally jarring every time I see it in my code. Even though I'm pretty confident in myself to properly check this every time I use it, my brain shouts "BUG!" when I scan through my code
Well it's where rather than wherenot in the sense that the "first" arg (df1) is used when the predicate is True, elsewhere the "second" arg (df2). But it gets extra pathological when there is no "second" arg and you only have df1.where(cond). And the two args are separated into instance + parameter, which makes my brain bump
In any case you're not crazy (in this regard)
Hahaha, I like the edit, I was just typing that bit for you :P
better to only make technically correct statements :P
Sure, it definitely was for that reason and not any kind of implications :P
16:13
@Kevin I've done this very thing in the past to crunch some text down to a somewhat smaller chunk of text. zlib or lzma can crunch down to 15% of the original (I think I was packing the text of Richard III), then base64'ing doubles it (each byte requires 2 characters), so you still come out with a reduced size string.
@TST20241 googling "python voice recognition" turns up a number of promising-looking links and YouTube videos
user14596741
Guys
16:28
Hello everyone, I am looking for some guidance regarding IIS trusted connections with my python app
user14596741
is IIS closed source, i searched it is made my microsoft?
yes it is the microsoft version of a web server
user14596741
Please dont mine, it is not answer, i dont know about it but I recommend use opensource alternatives
https://www.topbestalternatives.com/microsoft-iis/
(can't believe that was 2006!)
Gosh! That's one of those songs that fell into the well and you're playing the role of Lassie to remind us it's still a concern :)
user14596741
16:39
but now there are only song that are very like minaj anaconda. People shows body instead of song quality.
Have you ever worn the mask one-two one-two,
(M) to the (A) to the (S) to the (K)
Put the mask upon the face just to make the next day
seems quite apt today as well... good ol' Fugees :p
Someone must have parodied that now for the fun that is 2020...
16:50
I saw this in a code site for printing a linked list, def __str__(self):return f'{self.val} -> {self.next_}' in Node class, I didn't even know recursion could trigger implicitly
formatting defaults to calling str on the fields.
So it's equivalent to def __str__(self):return str(self.val}) + " -> " + str(self.next_)
@MisterMiyagi two missing spaces :'(
and a missing line feed ;)
hush :P
that makes sense, thanks, better than the while cur loop solution I have been using all along
@python_learner it's not exactly trivial for me to read, for what it's worth. I'd probably write a generator that yields node names (or the same in just a list) and then feed that to ' -> '.join
with, of course, some sane non-recursive __str__
16:55
Yeah.. not convinced having __str__ do that is that useful for a linked list...
should be a dedicated method so you definitely know you're asking for it instead of print(some_linked_list) going wild...
and if someone happens to close the linked list into a cycle, well...
that would still happen for a loop based solution wont it?
@python_learner yup, if you don't catch it
but for instance with a loop it would be trivial to have a set of seen nodes and stop once you hit it
yeah it was one of the beginner questions they taught us, find cycle in linked list :D
whatever I find "cool" on the internet is bad practice :/
@python_learner that's a valuable life lesson
17:02
laurel, alright room 6 have a happy weekend
Jul 27 at 14:35, by Kevin
Brian Kernighan, if wikiquote is to be believed. "Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? "
4
@python_learner Most valuable lesson here ^
thats deep :O
have a good weekend
@AndrasDeak O(n) solution with O(1) memory is to use 2 iterators. Bump iter1 by 1 for each step, bump iter2 by 2 for each step. If iter2 reaches the end before iter1 == iter2, then no cycle.
@PaulMcG good to know, thanks :) I just meant a failsafe in a recursive __str__ scenario that can run away
17:10
Yes, I'm guessing that surprise recursion in f-strings will start to crop up as an insidious anti-pattern.
You misspelled "cool trick"
Style Rule 28: Any programming "cool trick" must be earned by performing an equally "cool trick" on the half pipe.
17:37
Aug 28 at 10:10, by roganjosh
When I was at Tesco they had a board in our office for "days since last unicycle accident". I thought it was a joke... nope. One of the guys had a unicycle and they used to all practice in the car park at lunch
Would you consider that as equivalent?
Otherwise, it seems like the standard might need updating from the 90's
@AndrasDeak Very true. Hear, hear!
Oddly, I think a 2020 reboot of that style guide could be remarkably effective. "Any cool trick must be accompanied by a selfie with 3 cool Instagram filters of you implementing it". That'd be enough to keep it out of my codebase
@roganjosh Consider "cool trick on a unicycle on the half pipe" as worth double points.
My brain has wandered... I wonder if you can create a python script with images embedded in it
@MisterMiyagi worthy of that cute asspression trick
17:51
This suggests that you might get away with a Rich Text Format to embed an image. I don't know whether I want to explore this silliness further
99.9% chance of failure to get something that actually displays the image in (any) editor and still actually run as a python script.... I'm kinda liking those odds
Use the bytes->ASCII trick we talked about earlier this morning. Or create an import hook so that you can just import them as a variable, and let the import hook do the image->bytes work.
I just did a small Python project for my son (Assoc Art Director for a game company in Denver), to make it easy to do quick image markups for notes back to the artist. The test images I had were easily viewable in PyCharm (though as separate files, not as Python code content).
First time in a while that I used pyinstaller, it is really pretty easy, and even pulling in wxPython the resulting exe was only 13MB in size.
With the import hook to convert to say a PIL Image, you could do something like import lena; lena.image.show()
I actually think I might have a go at this because it's totally and utterly outside of my understanding of programming in general, so I'll learn even if I ultimately fail... but the goal of getting some person in a T-Rex suit trying to fish or something might be enough to spur me on
I did a crude demo using an import hook to import a .txt file, exposing the content as module.text.
@PaulMcG I'm a little confused what the gain is for that over just loading the image and then showing it?
Might be useful for images that are static, to be deployed with your package. Module/file resolution and import would take care of all the dir and permissions bits.
... maybe???
Or at least a cool trick?
18:05
I'm err'ing on the later :)
sigh <goes to the unicycle shed>
Does anyone know of any real-life import hooks that add actual value above just explicitly reading and processing the file contents?
@roganjosh If you did the embedded bytes->ASCII, you could then write a PyCharm plug-in to detect those variables and do the image display right in the IDE. Let us know when you've got it done.
@PaulMcG lena.image.show() relies on the python interpreter, though?
I've not seen any - I'm also struggling to think of a use of it
@PaulMcG hahaha. Not only is the goal totally ridiculous, but you're cheating to get to it!
18:12
The import hook would read the lena.jpg file into a PIL Image, and return a name lena with a single attribute image. I don't recall what the method is on Image to show it, but that is the idea.
one possibility is that you want to import X where X could be from a known source control system (based on some explicity set environment settings), shared on the local system, or local to the user... and you need to pick which... but - that's mucky...
You would first import the jpg-reading import hook, like import jpeg_importer, then you could do the import lena code.
or you might want some really weird construction of being able to explicitly import from a certain version of something... so import X__1_2_3 versus import X etc... and use an import similar to how pip automatically does the latest unless explicitly told `X==1.2.3" or something
mind you... those are just crazy ideas...
You mean crazy good right? Like an infomercial where you can't open a cupboard without being killed to death by falling cereal boxes. These problems are real.
Hi everyone! Trying to create a regex to match markdown code blocks. Found this one: ```[^\S\r\n]*[a-z]*\n.*?\n```. Trying to modify it to match code-blocks starting with \t or 4 spaces: (```[^\S\r\n]*[a-z]*\n.*?\n```)|(^\t). But it doesn't work ( How to fix?
18:21
pyparsing's statemachine example includes an import hook that searches for special statemachine State: <followed by state definitions and transitions in parseable form>, replaces the statemachine syntax with generated Python classes, then compiles and returns the full module.
But again, this is of questionable value when you could just parse a string with that same syntax in your regular Python script. It was more of a "could I do this?" experiment in response to two related Python talks at a PyCON
@PaulMcG I think the thing with Python is that most of the time the question of "Can I do this..." - is mostly likely "yes you can". With the disclaimer of: "you most likely really don't want to though..."
@VictorVosMottor there's a few markdown parsers already built - have you tried those?
I think there's smaller ones but you can possibly even re-use the markdown parser from the sphinx documentation library or something like that?
@JonClements maybe, but I'm doing some strange thing: finding code-blocks, replacing them with [[CODE1]] [[CODE2]] etc. than apply spelling corrections to the text than replace [[CODE1]] [[CODE2]] etc. with the original code-blocks. Why? To keep code as spell checking library thinks it is just regular text in English. ;)
@VictorVosMottor looks like you could use commonmarkpy.readthedocs.io/en/latest to parse the markdown, but have it as an AST, then run against the various nodes your checks to modify those, then finally output?
@AnttiHaapala >:|
Passes my cromulency check
@JonClements seems to be good, thanks! ;)
18:52
user image
3
^^ the wages of cos
AAB
AAB
19:18
Hi all,
I have a string, I have 5 conditions if it matches 1 then I stop and categorize it, if it does not match all 5 I add some default value. the following can be done using if elif else but any better way to do the same?
Like say I send the string to some pipeline that has some rules on the first match it stops else it keeps applying the remaining rules any library etc that I can use to achieve the same ?
Way too vague. What are the "conditions"?
AAB
AAB
@roganjosh I have a list of strings I apply Sequencematch(difflib) for the list and target string see if the ratio is >= 0.8
for match, action in zip(matches, actions):
    if match(s):
        action(s)
        break
else:
    default_action(s)
Create a list of (condition, category) tuples and loop over it until one matches
yeah, that
@AAB I'm just confused now. Why would there be a library for if/elif/else checks when you review the comments above?
19:29
sometimes the obvious solution is only obvious in hindsight
AAB
AAB
@AndrasDeak In the sample you provided for each string if match(s) is False it goes default_action(s) am I right?
@AAB yes
hence the name ;)
AAB
AAB
@AndrasDeak @roganjosh what I want is like string does a match if not True next rule/match if all 5 don't return true then I set a default value.
@AAB indeed
Please just give an MCVE. I feel like, in recent weeks (so not just you), we're chasing ill-defined problems
19:34
@AAB perhaps I mistook what you said, thinking you phrased the correct behaviour wrong. What it does is "if all matches are False it will go to the default_action".
AAB
AAB
@roganjosh the way I was planning was to add if elif elif.. else but then for each condition I would have an elif
hence "hence the name"
@AAB which is not extensible, as you've discovered.
AAB
AAB
@roganjosh sorry let me give an example: say string is cherry mx blues keyboard, now my match conditions could be like IsKeyboard, IsCPU, IsGraphicsCard, IsMotherboard
if it does not return true for any I just label it as others.
That clarifies nothing to me. Maybe there is context behind all this that other people remember, but I don't. That's not an MCVE
FWIW string parsing is not my game and is better handled by other people. But I can usually get a grip on the question, even if I couldn't have come up with the answer myself. I don't know what we're discussing here
For example, in my head, you're mapping this to a pandas column. Are you? Probably not, but the context is left wide open so my brain frames it however it wants
AAB
AAB
19:45
@roganjosh Let me post a small example
@AAB - the loop posted by Andras does exactly what you want. If any match matches, then the corresponding action is run. If all the matches fail, then default_action is run. Don't be confused by the else, it is not an else for the if match, it is the else for the for loop, which gets run if the entire loop runs without hitting a break.
AAB
AAB
@PaulMcG thanks yes @AndrasDeak clarified on the same too. I got it, I learned else can be used with while loops too :P
adding example just clear up any confusion :)
Despite my best efforts we're sliding deeper and deeper into September
00:00 - 20:0020:00 - 22:00

« first day (3681 days earlier)      last day (1491 days later) »