« first day (4066 days earlier)      last day (865 days later) » 

rob
1:08 AM
Hello, room. I have a snippet of Python3 code which is basically
for line in stream: fields = line.strip().split(',')
If the stream comes from a regular file, this is fine. But if the stream comes from ZipFile.open(), the iterator returns the lines as byte objects instead of strings, and barfs unless the splitting parameter is b','. Is there a straightforward way to be agnostic about str vs. byte, so I don't have to write two versions of this function?
 
rob
1:21 AM
One solution seems to be to open the regular file with binary mode 'b', then do for line in io.TextIOWrapper(stream): to get strings, plus some insulation against newline weirdness.
 
 
2 hours later…
3:33 AM
Need some assistance with this: i.postimg.cc/tCqscRvZ/image.png Can anyone tell why the file is not found? It's clearly in the directory
 
3:46 AM
Nevermind, I diagnosed the issue - I didn't os.chdir to the directory earlier
 
 
6 hours later…
9:58 AM
Morning all
 
10:16 AM
cbg :)
Is that two days in a row @OldTinfoil? You're at risk of becoming a regular or something :P
 
10:26 AM
Cbg
How is everyone doing ?
 
Well, less than 24 hours. It's a dangerous precedent xD
Today is going well. I have tamed the error callbacks and they now do my bidding. Until my back is turned, later.
Yourselves?
 
11:21 AM
Trying my best to keep my sanity with Word/Excel/Postgresql
 
11:32 AM
Not too bad thanks. I took today off and woke up to errors on our workflow - someone's managed to set off a query on our cluster that takes up 200GB of space in temporary tables and only stops because the cluster hits its limit. Alas, I don't think I have enough privileges to find the culprit. Can't wait for that to run like a cron job
In other words, standard day :P
 
Quite an impressive query
 
It really is. I wanna know how they've managed to inflate it so much. Cross-joins on cross-joins?
Even better, I don't even know when it would have actually stopped. The graph of disk usage just has a linear trajectory to 100% and then it's killed. How much further could it go?
 
to infinity, and beyond
 
:P
It would be helpful if someone from engineering/devops would take this on... but, yeah
 
Some people don't take resources into account sadly
 
11:40 AM
I think it's a genuine accident but it took out my process so I made it public. I doubt they'll want to own up on a company-wide thread in Slack
 
Reminds me of a devops tech taking down a production server on a Friday evening because of an OutOfMemoryException, said server having 64Gb of RAM and 20 of swap
 
You need an extra 0 added on to your swap (apparently) :P
 
so that it would run till saturday morning before being taken out. :P
 
Ooo, someone did just own up. BBS
 
commend them for owning up
 
11:46 AM
Looking at it, I don't think it's true. I think someone is owning up to something that wasn't them!
 
ah, the over eager own upper. i did wear the wrong shoes to work yesterday, maybe the earthquake was my fault after all!
4
 
I didn't even do my good cop/bad cop routine to get a fake confession!
 
Is a company-wide thread a mess or on the contrary almost totally empty ?
 
12:10 PM
We have hundreds of channels on Slack. In this case I shared the error on a thread that basically the whole company is subscribed to. It's not a mess, but there's a lot of notifications across the channels
 
12:26 PM
hey guys, is there any python module that will automatically take care of creating a new token using a refresh token for oauth?
I do not want to keep track of the expiry time of my token, so basically I tell the module to refresh if my next api call is past the expiry time I set
 
It's been a few years since I researched oauth modules, but back then I didn't find any good ones
 
that is not promising to hear :( I guess I can search for some answers on this site then, I was hoping requests would do this
 
1:18 PM
cbg!
so I was wondering...I'm halfway through converting some python2 script to 3.8 locally, and noticed some of them use xmlrpclib. I'm well aware the equivalent import on py3 is xmlrpc but it seems like it miss some support for certain stuff. eg: I need to convert a line such as from xmlrpclib import ServerProxy, Error as XMLRPCError
but only could find 3 to 4 things I could import from xmlrpc...any ideas?
for ServerProxy, it seems like server from xmlrpc would work, but what about the rest of what I posted above?
nvm, I think I figured it out
seems this is the equivalent: from xmlrpc.client import ServerProxy, Error as XMLRPCError
anyone got that one special project they want/need to finish before New Eve? or something like that
 
1:38 PM
@NordineLotfi me, yes.. but I think I'm not gonna be done till march >.<
 
@Roadman1991 same. In my head I think "gonna finish in a week" but it end up being a month...
 
I have so much bad behaviours when programming... like for instance, when I code something and already know that this is never gonna run I run it anway xD
 
I wouldn't call that bad behaviors but then again, that's maybe because I do this too, so maybe I'm biased
 
As if finished projects were a thing
 
right, let me rephrase it: anyone got that one special project they want/need to set to a stage where you are proud/content of it's basic feature(s) but still plan to not finish before New Eve? or something like that
better?
or I guess easier on the mouth/mind would be: something you want to do in python before New Eve?
 
1:44 PM
Well I would like to finish my horror game before eve
 
is it in pygame? or smth else
 
but my project at work is killing me^^ 8am to 8pm all the time, exhausting xD
and when im home i play 1-2 rounds AOE4 and the nim done for the day, im soo lazy xD
na with unreal engine^^ unfortunately not python related^^
 
@Roadman1991 ah, gotcha
 
If I look at my github, I really would love to finish my python project where I show present data visually about corona numbers etc.
Am I allowed to share yt links here in chat?
https://www.youtube.com/watch?v=hgI0p1zf31k
PEP8 song xD
 
that first part of the song though: you don't need any curly braces~ what do you mean, what about my precious dict??
 
1:53 PM
im wondering aswell... is there a pep pythonic way without curly braces?
 
I guess, maybe if you directly use dict() instead of doing var = {} but that wouldn't really make sense if you do it all the time, in most cases
 
@NordineLotfi he says no curly braces for open spaces
 
haha
 
I just noticed, but python lexer/ast really act weird sometimes. eg: there error in both import statement at the top and in the middle of the file/code, but upon running the whole file, the first couple errors reported will be the middle part of the file, not the top/import statement
is that normal behavior for python or?
I only notice this sometimes mind you, so it's hard to reproduce on my end
 
1:59 PM
Is it an actual syntax error in the import statement, or just some error inside the imported package?
 
it's not just syntax error; here I'm talking about it generally because I worked with a bunch of errors (beside syntax error). Also it's inside a local script split across multiple file/sub import
so errors are a bit spread around and I fix them as I go
also, one of the time this happened to me, it was mostly missing import, but I only got the error about it at the far end, after fixing a bunch of other error in that same file...
 
SyntaxError will always be reported first. It gets triggered before the code is even executed, so no runtime errors can trigger at that point.
 
ah, then this is really weird
 
Things like missing imports will only trigger an error when the code actually uses the missing module. Python doesn't know where you intended to get a name from.
 
yeah, but I think it does use it? eg: at the top it try to import missing import but the error sometimes doesn't happen right away when running the file for whatever reason
it only happen after I fixed every other bugs in the file beside the import statement
I wish it wasn't so hard to reproduce though, otherwise I would have a testcase to show off here
 
2:09 PM
It's not difficult to make your program blow up half way through
class Something:

    def __init__(self):
        print("hello")

    def do_something(self):
        import xyz


a = Something()
a.do_something()
 
oh, I see what you mean yeah; the class/function would load it later on instead of at the top, yeah
I guess this might happen here too since I'm seeing a bunch of import used later on in some class/function too. Not sure 100% yet but this is the most plausible explanation :)
 
@roganjosh It should be difficult to write such code for every mannerly minion. Perhaps the restraining bolts are bugged...
 
@MisterMiyagi I saw this kind of writing on a bunch of third party modules; eg: bpython, jedi, etc. I think it's easier to write that than to read it (speaking for myself here...) on a friday night
but if you squint your eyes, I guess it does make sense
 
So does PERL...
 
@MisterMiyagi My gut feeling is that this restriction would trash Python, though?
It goes even further than type checking, now you need a compiler?
 
2:16 PM
Heresy! Let me fetch the pitchtorches...
 
:P
 
@MisterMiyagi Perl's quite tough to handle at first
 
It's also quite tough to handle later on...
Doesn't beat having socket buffer errors that only trigger above 100 concurrent tasks, though.
 
It's funny you say that; I had a bunch of them yesterday when working with sockets
 
We should all switch to IPoAC. Much less of a hassle.
 
2:19 PM
Is it ok to mark a dupe if the OP is misunderstanding how to implement it in their own code?
 
My Rust ambitions have hit a snag. I found this code and that's sufficiently alien to me to be concerned that the library would be unmaintainable by newcomers
(Not that I think I could even write it myself, currently. But I can learn)
 
@roganjosh || mark lambdas, if that helps.
Otherwise it would look pretty similar in Python, though using prefix instead of postfix for functions vs. methods.
 
Yeah, I've found the closure documentation that kinda explains it.... but, man, that's tough going for an outsider. I don't know whether it's idiomatic, though
 
It matches what I've seen for iterators.
Doing last years AOC with Rust really helped in that regard.
 
If I try to do sqrt(2) in the middle of my file, I would prefer it to say "can't find anything named "sqrt"" and point to that line, rather than point to the top line of the file and say "try importing something here so sqrt exists". If It's been a while since I wrote the code, I might not even remember where the sqrt call is, and it's easier to just ctrl-G and jump to the line rather than ctrl-F for all sqrts
 
2:21 PM
@MisterMiyagi That's what I'm trying this year thanks to you laurel
 
@Axe319 if the dupe in question is related to what they want to do or/and if you think this could fix their problems...I think so?
 
@MisterMiyagi That's a great shout!
 
@Hakaishin @Aran-Fey just fyi from yesterday, turns out one of the other manager reviewed my merge request and the autoescape tags were not needed. All I really required was a filter called safer and that all works too.
"description": "{{ project.description|safe }}",
 
@Kevin yeah, I had similar problem myself, although it was a mixed bag with delayed import error, so not sure if fully related (mentioned it earlier in chat)
I can't even reproduce it easily so I guess the only harm it does is confuse me
 
2:23 PM
@roganjosh Just trying to be subtle as always. :D
 
@NordineLotfi As far as I know, Python will never try to guess what import you forgot to add and import it for you. Maybe a smart NameError will say "can't find name sqrt (did you forget to import math?)" but you still have to add the import yourself
 
Have you registered your github MM for this year?
 
I've only had time for two days of quick and dirty Python so far, sadly.
 
@NordineLotfi Well if you run into it again, please share, because I love a good weird import problem
 
@Kevin yeah, for my case it was a bunch of non-installed import at top of file, but their error didn't come until I fixed every other error (that aren't import related) in that same file before I saw them in the stack trace
 
2:26 PM
My favorites are when A imports B, and B tries to import A, which doesn't necessarily cause a crash but it can cause the code to execute in a surprising order
 
I think im facing an impossible to solve problem now at work :(...
 
@NordineLotfi classic circular imports. I do have to ask why you're debugging multiple syntax errors at once, though?
 
@Kevin sure thing. It's hard to reproduce verbatim, but what I did is: git clone the bpython project, git checkout to oldest version number (0.9.4-release) and try to convert it manually to python3 (I'm on 3.8) BUT, leave all the import statement to be fixed only when: 1. the error appear, 2. when you fixed every other error that arise
@roganjosh for multiple reasons :) but one of them is closest to "fun" :D
 
Your IDE will flag almost all syntax errors as you make them, and it's not good to write like 100 lines of code without checking it
 
well, I guess another one is "learning" but yeah
@roganjosh actually, I'm using a mix of cli and gui IDE/editor, so there isn't always full python support anyway
(I vaguely recall saying I hop editor a lot before)
 
2:30 PM
Perhaps you did
 
@NordineLotfi I'm only using pyCharm and visual studio code so far.
 
@Kevin I also noticed one of those in my adventures (if you can even call it that)
@Roadman1991 tried both but there always something that irk me and I end up hopping to something else
 
really? I'm missing really nothing with them, both great. VSC is also very lightweight.
 
+1 to VSCode
 
Oh, IDEs are a factor when it comes to the order that errors are brought to your attention. In the regular old command line, You'll always see SyntaxErrors first, and no other kind of error until you fix all of the SyntaxErrors in the file you're running. But if you're using an IDE, it might be smart enough to identify SyntaxErrors, and then scan the remaining syntactically correct code for possible problems.
An IDE might also be quietly inserting import statements without telling you. Basically anything goes.
 
2:34 PM
@Kevin yeah, but the funny thing here is that I wasn't depending on an IDE error's checking (since some of the one I hop to doesn't support that for python). So I was kinda surprised/confused on those delayed error
 
@Kevin I might be alone on this but I really don't care for IDEs sneaking code in I didn't write.
 
Mm hmm, that's one of the reasons I stubbornly continue to use Notepad++ and cmd
 
When I was on windows a couple months ago, I also ended up only using notepad++, although I was a bit tempted toward pycharm at some point so I guess it doesn't count
 
@Kevin
I tried that in pyCharm now. SyntaxErrors come first before any syntactically corret code.

print(some_float[0])
if True
    pass
 
The only secret changes that Notepad++ makes to my files is when it converts my "\n" newlines into "\r\n" for the purposes of OS intercompatibility. I think I opted into that one.
 
2:41 PM
the syntax error was only shown with the missing ':' before the print(some_float[0])
 
Interesting
 
I love N++ but I use VSCode for all my work projects. I still use cmd or batch files for running the projects and unit testing though.
 
I noticed 4 or so inconsistencies (want to call them bug but meh) when it comes to pycharm autocompletion and syntax error. For some reason it doesn't always autocomplete certain things right, like constraint or constants, or even decorators...
also feel like the windows build is much more stable than on linux but maybe that one is just me
ever felt like a bug magnet? It feel like this is always the case for me hmm
 
@Nordine no it's not just you.. I feel like that often ^^
 
@AndrasDeak I was worried about the discreteness, but I thought I might be able to hack together a continuous version. Binomial coefficients can be defined in terms of N choose K, which can be defined in terms of factorials, and factorials can take non-integers... So that's like 60% of the work done right there
 
2:54 PM
@wim :D 𝛾, ε
 
cbg-afternoon
 
Found a way to get softlocked in Excel, didn't expect that
 
3:12 PM
I've got a csv file that my method transform, charging them into a dictionnary like this one {1: "Vue network", 2: "Blockbuster"}.

I've got another dictionnary where I have this {1: ['Mann theater','LA','vue network'], 2 : ['Apollo Theatre', 'NY', 'Blockbuster']}

My aim is to change the values in the second dictionnary using the first dictionnary, change Blockbuster or Vue Network, to respectively 1 or 2.

Not sure how to do this. If you got a hint, I'm all ears.
 
@AndyK maybe I have something for you, If I understand right you want to map dict1[0] as key with dict2[0] as value?

settings_dictionary = dict(zip(settings_keys, settings_values))
 
@AndyK so you want {1: ['Mann theater','LA','vue network'], 2 : ['Apollo Theatre', 'NY', 'Blockbuster']} to become {1: ['Mann theater','LA','Blockbuster'], 2 : ['Apollo Theatre', 'NY', 'vue network']}?
 
@NordineLotfi nope {1: ['Mann theater','LA','2'], 2 : ['Apollo Theatre', 'NY', '1']
 
ah, gotcha
 
aaah got that too now^^.
 
3:19 PM
There must be something simple but right now, I don't have any ideas.
 
using a for loop + a dict with the two values, and their respective number would work imo
or map if you know how to do it with that hmm
 
General advice: if you have a dictionary whose keys are consecutive integers, then you should carefully consider whether you can replace it with a list
Sometimes you can't, but many times you can, and the rest of your code becomes easier to manage as a result. Dividends!
Hmm, I am confused. Why do you want to change Blockbuster to 1 and Vue to 2, when in your first dictionary, 1 maps to Vue and 2 maps to Blockbuster?
 
I'm guessing maybe they want to either reassign it to something else later on, so they do that to make it more discernible, or maybe they want to tone down using too many value/decrease size of list/dictionary by using numbers instead for certain value/string?
 
Ok, concision and/or memory usage are valid reasons for wanting to achieve the broad goal of "replacing strings with smaller strings". What I'm confused about is, how do you know that "Blockbuster" should be replaced with "2"?
 
3:34 PM
@Kevin the keys are in the first dictionnary, hence 2 for blockbuster and 1 for Vue
First {1: "Vue network", 2: "Blockbuster"}
 
I apologize, I mistyped. How do you know that "Vue network" should be replaced with "2"? Half a page up you said that when the input is (in part) 1: ['Mann theater','LA','vue network'], then the output should be (in part) 1: ['Mann theater','LA','2']
 
@Kevin I'm using the keys of the first dictionnary
 
I know. But Vue's key is 1, and your expected behavior is to replace Vue with 2, so there is a contradiction somewhere.
 
@Kevin my bad. Aim is to have 1 for Vue network and 2 for Blockbuster
 
Ok, cool
 
3:40 PM
if there is any confusion in the previous comments, this sets the point.
 
I have a rough draft solution written out. I just want to take a couple minutes to add some test cases of my own
 
@Kevin I would use itertools but I'm a bit confused about it
 
You could reverse the mapping of your first `dict` and then apply it to very `list` of your second `dict`.

Something like:
```
mapping = {v.lower(): str(k) for k, v in dict1.items()}

for key, lst in dict2.items():
dict2[key] = [
mapping[item.lower()] if item.lower() in mapping else item
for item in lst
]
```
 
string replacer v1.0 pastebin.com/aLf3xS2G
 
mine had two level of for loop + one if block but it didn't work so it's useless to show it :D (got stuck in the part where the value are assigned + two for loop ended up making two unneeded pass)
 
3:52 PM
Once again I see @Axe319 came up with the same idea as me :-) it's nice when me and my peers decide on the same approach, it's a good sign that we're not going on a wild goose chase
 
dict1 = {1: "Vue network", 2: "Blockbuster"}
dict2 = {1: ['Mann theater','LA','vue network'], 2 : ['Apollo Theatre', 'NY', 'Blockbuster']}
for key_dict_1 in dict1:
    for key_dict_2, values in dict2,items():
        if key_dict1 in values:
            #logic here
would that be a beginning?
 
@Roadman1991 I was doing nearly exactly that, but got stuck at the logic part myself
 
you just replace the key the string with the represented number
 
if key_dict1 in values: is unlikely to succeed because key_dict_1 is an integer and values is a list of strings
 
yeah, but I got stuck because it's a list in a dict (I know how to do it when it's either but not when it's nested like this...)
 
3:56 PM
You're basically doing if 1 in ['Mann theater','LA','vue network']:
 
main = {1: ['Mann theater','LA','vue network'], 2:['Apollo Theatre', 'NY', 'Blockbuster']}
other = {
	1: 'Blockbuster',
	2: 'vue network'}
for j in main:
	if main.get(j)[-1] in other.values():
		for k in other.items():
			print(main.get(j))
			#stuck here for assigning + two unneeded pass because of the two for loop
 
Oops, I forgot to actually inform Andy of my solution. @AndyK pastebin.com/aLf3xS2G
 
@Kevin soz, urgent family matter ... checking now.
 
No hurry :-) I just wanted to make sure my link didn't quietly disappear off the top of the page
In the past I've experienced a few too many "what do you mean, you posted a complete solution half an hour ago? What was the point of all our brainstorming since then?" scenarios
 
@Kevin I ran the method with main = {1: ['Mann theater','LA','vue network'], 2:['Apollo Theatre', 'NY', 'Blockbuster']} and other = {1: 'Blockbuster',2: 'vue network'} and the method is giving me this ...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in andy
AttributeError: 'list' object has no attribute 'lower'
 
4:06 PM
Sounds about right. My implementation works only when b is a dictionary whose values are lists of strings. Your other there does not have a list of strings, it just has strings.
[Issue closed as "Working as intended"]
I could make it work for both dict[int, list[str]] and dict[int, str], but I'll have to get the customer to sign off on the requirements revision
 
@Kevin ha ha
not that easy, after all
 
@AndyK I think the actual issue here is you have the arguments reversed. How are you calling andy?
 
@Axe319 like that andy(main,other)
 
[squint] ah, true. a should be a dict[int, str] and b should be a dict[int, list[str]]`. Your main and other are exactly the other way around
 
it does work ...
 
4:14 PM
[Issue reopened]
[Issue closed as Typo]
 
wow
 
[added "wow" to the project's Customer Accolades and/or Astonishment At Kevin's Smug Attitude page]
 
@Kevin can you explain a bit that part, please? {k: [inverse_a.get(item.lower(), item) for item in v] for k,v in b.items()}
you are actually doing a double loop through a dict comprehension, if I'm correct
 
Ooh, I didn't even think of dict.get. Much better than my ternary.
 
ヘ( ^o^)ノ\(^_^ )
 
4:18 PM
@AndyK I can show you the equivalent code that doesn't use comprehensions:
#this:
return {k: [inverse_a.get(item.lower(), item) for item in v] for k,v in b.items()}

#is equivalent to this:
result = {}
for k,v in b.items():
    seq = []
    for item in v:
        value = inverse_a.get(item.lower(), item)
        seq.append(item)
    result[k] = seq
return result
As you say, it is a double loop
(But not an O(N^2) one since they're looping through different things)
 
Indeed, I see that.
 
Basically 90% of the code handles iterating through b while keeping track of where you are, and inverse_a.get(item.lower(), item) is where it decides whether a value should be replaced or kept the same
 
I'm truly not that familiar, yet, with this kind of double loop when using different objects. But the idea came up instead of doing call through database
 
Mm hmm, it's certainly possible to do many database-like things using only built-in types
Almost everything, except for "be really fast" :-P
 
@Kevin so it's similar to what I did earlier but it actually work :o does your code handle the unnecessary/unneeded two pass caused by the two for loop?
 
4:25 PM
I still don't really understand how databases can speed up by using indexes. I think it might be computer gnomes.
 
not really sure which part is the easiest, calling through db or parsing through two dicts. But as I'm supposed to be loading the final dict into a db, that would be quite dumb to do a db call before charging the final dict
@Kevin This dict is supposed to be charged into a db
 
@AndyK you could look at db implementation in pure python on github; some of them are a bit hard to read but they might give some ideas :)
 
@Kevin "Any sufficiently advanced technology is indistinguishable from magic."
 
@NordineLotfi compared to your approach at chat.stackoverflow.com/transcript/message/53578809#53578809, mine only iterates through a (aka other) once, while yours iterates through it len(main) times. Not a big deal since a/other is so small, but yeah
 
@NordineLotfi that will be fine. It is more for testing now.
 
4:29 PM
@Kevin Doesn't it basically just boil down to the fact an index is a binary tree that more natively resembles your query than the binary tree the data is stored as?
 
Plausible, but I would need to color in many blank parts of this mental image, before I could really get a feel for its performance impact
 
@Kevin ah, yeah you're right :) Thanks for the explanation
 
Perhaps my inverse_a could be thought of as an index on the a table, to make lookups-by-value as fast as lookups-by-key
Everybody's proposed solutions are doing something like table B left joined on table A, but mine skips a little work in the loop by doing a little preprocessing
 
4:55 PM
@Kevin btw, I'm uploading the code I ported so far to py3 (following the weird bug I mentioned earlier). It's too tempting considering I just got a new weird one: there a function main() but it's the last one in one of the file (main file) but some variable I'm printing outside any function is empty, even when using type on it or printing a simple string....
I ported only a couple py2 script to py3 in the past, but this is by far the weirdest compound of cases I ever seen
 
It's quite unusual indeed when print(type(whatever)) shows no output at all
 
yeah, and even a normal print('string') doesn't work at all even though it's outside a function
 
Typical causes: print or type have been reassigned to functions that don't do anything useful; sys.stdout has been reassigned to a file-like object that's not related to the normal output window
And the classic "the line containing your print call is never executing at all"
Perhaps because of a sys.exit() call earlier on, or an exception raised by one module and caught/silenced by another
 
you don't mind if I use gist even though there more than one file? (didn't amalgamate them so it's easier to read)
 
I'm fine with that
 
5:14 PM
here: https://gist.github.com/secemp9/7eac201cbee365540130e5059ca233d1
main file to run is `cli.py`. As mentioned I already fixed a couple bugs but there still a lot left, except...for the weird bugs that surprised me/confused me
(and still are)
just running it, you'll notice that it might create a huge block of whitespace, which are basically the attempt at simply printing some string outside function/class in that same file...
 
The first thing that pops is orig_stdout = sys.__stdout__.
 
I also have a gist, showing something I just learned: gist.github.com/kms70847/496802a4954f2f1f2cbdf29062079d07
 
@Axe319 yeah, that one is weird but, I didn't see it yet because: the only error I see when running it are the two weird corner cases I mentioned, since I attempted a porting the hard way plan, by basically squashing one bug at a time, without relying to external linting tools (just normal python)
 
Since c.py does nothing but import a, you might expect python a.py and python c.py to produce identical output. But they don't, presumably because Python doesn't apply its magical module caching to the main file until it decides that it's necessary
 
It's because the file you execute gets the name __main__, so import a executes a.py a second time
 
5:20 PM
@Axe319 That's a classic sign of stdout redirection, yep
 
@Kevin from what I gathered, they're doing this because of a weird workflow around curses/input basically, but I'm not fully sure yet
 
@Aran-Fey So a.py is cached, but import a can't find it because it's not looking under __main__? I wonder why they don't cache it under both __main__ and a... Maybe choosing a non-dunder name is ambiguous
 
Correct, import a looks for "a" in the module cache, but there's only "__main__" in there at that point. Registering the main module as both __main__ and its actual name would actually be an interesting idea
 
gist.github.com/secemp9/… is the other half of the redirection recipe. Whatever repl is, it's not putting characters on your screen
 
yeah. But I'm curious, how come the couple print statements I placed for debugging at gist.github.com/secemp9/… (the cause for the whitespace maybe??) when running the file cli.py
I can face some weird delayed import error, but this one, it confuse me
 
5:29 PM
I suspect the working print calls happen before stdout gets reassigned, or after it gets restored to normal
 
oh :D
that would explain so soo much
 
gist.github.com/secemp9/… is where it gets restored
 
I see. So I guess my plan of fixing bugs one error at a time won't work because of this hmm
so that mean I have to actually seriously study the code instead of putting it off after I port it to py3
 
Unnecessarily complicated debugging strategy: create a custom file-like-object class that writes its output to two file-like objects. Then you can do sys.stdout = CustomThing(sys.stdout, repl), and print calls will appear both in the console and wherever repl is writing its stuff
The console might display things in a weird order if curses is meddling with it, but it's better than a blank screen
 
Creating an arbitrary class to assign attributes to it seems a bit odd. Maybe they preferred it over the dict syntax? gist.github.com/secemp9/…
 
5:39 PM
yeah, I vaguely recall they planned some use for it in later version (since this is the oldest version that I could find on it's github). There a reason why I choose the oldest one but yeah
the latest one work fine on py3 except: 1. it isn't dependent on only local packages anymore and pull many third party deps, 2. it is relatively slow for something made in curses, but that part is maybe just me being biased, 3. I wanted a working example in pure python (only local package) of drop down menu + completion with curses
of course, I already know how to do autocompletion using input, but problem is, I struggled to find a minimal example of this for more than just local() and global()...this fits all of the requirement
@Kevin Thanks for the idea, guess I'll try that :)
 
I may have a quick question i thats fine:


execute_string = "SELECT * FROM checked_alias_files"
cur = con.cursor()
rows = cur.execute(execute_string)
print(type(rows))
for row in rows:
print(type(row))
print(row)


is there an easy fast way to save this into a dict, I want to change every value from 2 columns later on.
uhm sorry for formatting, it kinda didnt work lol
 
6:07 PM
forget it^^... unfortunately I can't dlete it anymore xD
 
6:37 PM
@Axe319 I see people use that pattern every once in a while. These days you can use types.simplenamespace instead.
@Roadman1991 Consult tinyurl.com/urnzp7k for typical reasons that formatting doesn't work. Not that it's a big deal, since you only have one loop
What does print(type(rows)) show? I didn't know cursor.execute() returned anything
Ah, the docs says it's a shortcut that makes it easier to get row objects. Ok then.
Try all_data = [dict(row) for row in cur.execute(execute_string)], that ought to save* your data in a useful format
(*in the sense that it puts the data into an in-memory data structure that won't change even if the database is altered or deleted. It won't actually save it to the file system or anything. Consider json.dump for that.)
 
6:56 PM
just found out the source of the huge block of white-space: line 2240 :o progress~
commenting that and every other mention of stdout now let's me debug things correctly...
 
as I said forget ^^ I did that already @kevin
in a very complicated way xD
 
 
1 hour later…
wim
8:11 PM
@AnttiHaapala stalker! ;)
 
 
1 hour later…
9:33 PM
@Kevin does that actually work?
 
@wim btw fedex delivered my swag last week.
 
10:05 PM
I have a some data in a .properties file which I'm using config parser to populate into a json string to be a field in the post payload to an API endpoint
For example

[mysection]
username=admin
password=password
license=123\n456\789
 I would want to have the following:

    '{ "username": "admin", "password": "password", "license": "123\n456\n789"}'
If I print I want to see {"username": "admin", "password": "password", "license": "123\n456\789"}
i.e. the newline that appears in the config file would be retained as a literal
However, after using config parser and doing json.dumps to wrap the whole thing in a string that's not the case. How do I avoid this?
 

« first day (4066 days earlier)      last day (865 days later) »