« first day (3407 days earlier)      last day (1540 days later) » 
06:00 - 21:0021:00 - 00:00

6:24 AM
If I try to access a class variable from another class, then I get an error that ClassName is not defined. Is this not allowed in python?
 
It is. Sound like you either made a typo or didn't import the class
 
6:39 AM
The other class code was beneath the class where I wsa tryingt o use it. sorry my bad
move the code around made it work
 
 
2 hours later…
8:55 AM
Hi all, to check whether a variable is string or list, which is good approach: 1) isinstace or 2) type ?
and for type is it good to use == or is?
 
this should cover anything you might want to do
you can use is for explicit type(thing) equality checks, but it's not quite as clearcut as for None
 
I foresee at least two opportunities for pandas canonicals in the near future courtesy 1.0: object vs string, and np.nan vs pd.NA
 
hi everyone!
 
Hello
 
just a stupid questions, im starting with flask
and do i need a secret key to upload files locally?
just trying you know
 
9:09 AM
I think you need secret key when you use things like sessions. What else, Im not sure
 
no, no secret key needed unless you write logic that requires secret keys. uploading files shouldn't really be a question directly related to flask anyways.
 
By locally do you mean localhost?
 
hi
 
@M.Mariscal - this is helpful stackoverflow.com/questions/22463939/…
@MisterMiyagi Wish there was a 2line summary
 
yes localhost sorry
 
9:12 AM
@variable It appears they already found that, since they've posted under Martijn's answer
 
ok thank you so much, just im getting the error of secret key thats why
 
Getting an error where?
 
yes i already read it ;) @vari
@variable
 
Are you using other libraries like flask-session or flask-login? Or even just trying to use the regular session
 
not, anything like that, just from flask import Flask, flash, request, redirect, url_for, send_from_directory
from werkzeug.utils import secure_filename
 
9:16 AM
@variable Added a 3 line TLDR.
 
@M.Mariscal Which library is throwing the error?
 
is int a singleton in python?
 
@MisterMiyagi Thanks - so isinstance will handle cases where 1st argument is a derived class of 2nd argument?
 
File "D:\Users\str_leu\Documents\PycharmProjects\flask_tutorial\venv\lib\site-packages\flask\sessions.py", line 103, in _fail
"The session is unavailable because no secret "
 
Ok, so it is trying to access the session. I'm looking at werkzeug and not sure that it will cause an error with secure_filename
 
9:19 AM
@variable yes, isinstance handles subclasses
 
@M.Mariscal maybe due to cookies? @ParitoshSingh
 
control + shift + r isnt removing it?
 
for me a " " " " is added to the beginning of all questions on SO, anyone else is seeing the same thing?
 
@ParitoshSingh not a singleton, but there is only one int type
 
9:25 AM
i see
i was trying to reason out why you suggested type(x) == int vs is
Any particular reason?
@aderchox no, looks fine to me
 
@M.Mariscal Ok, I'm not seeing the cause in there. If you follow the traceback, you should be able to find the relevant line of your own code that results in the error. I'm curious what causes it
 
@ParitoshSingh yes it's fixed now
 
oh..I went back to the answer, and had a mini breakdown with a "did i imagine that all in my head" moment, before i noticed the "edited 10 minutes ago"
Don't mind me, thanks miyagi
 
@ParitoshSingh it's fine for builtin types, but in principle a type's metaclass can replace ==
I've changed the A to use is now, though
doubt that metaclass.__eq__ is what people expect to honour in this case
 
Cool, that makes sense
 
9:53 AM
@roganjosh at the end i did it, just i mixed some tutorials, i was catching from blueprints and files uploading and it was a mess, now i changed everything into the tutorial i told you and now just i have to guess where is my file jeje
thank you really so much for the help
btw i will have to learn airflow and snowflake, anyone knows any useful website or some info to know more about it?
 
10:05 AM
Good afternoon my lords & ladies!
 
hey @Alper
 
10:29 AM
Do I have to consider anything special when doing a check of -> named_tuple in list_of_named_tuples - does it check for equality of all tuple name/values?
 
named_tuple is a regular tuple with the addition of named accessors. so a namedtuple(a=2, b=3) and (2, 3) compare equal. In other words, it checks only for equality of values, not names.
this may be or may not be what you want
 
MisterMiyagi what is your experience year on Python
 
lessons I made while working with namedtuples
1: using namedtuple to avoid having hard to maintain stuff like `data[5]` in my code that I'd have when using tuples -> I had a good time
2: using namedtuple as the central data object in our business logic -> I had a very bad time
for the latter case, you might want to switch to something like dataclasses that behave a little saner
 
attrs is neat if you don't mind the dependency
 
it is. I also started using pydantic a month or so ago, and it's also quite good, even though its docs aren't
 
10:40 AM
@Alper I honestly have no idea. More than 2.
 
You have quite a good level of experience it seems or maybe trying to solve it for more than 2 years makes you very experienced
Stackoverflow actually a very good place to solve everyday problems for others and for yourself of course
Current python is very rewarding regarding the stackoverflow points
 
That's not necessarily a good thing. The python tag is swamped with dupes and poorly-researched/asked questions. The fact that there are people willing to upvote garbage doesn't help other site users even if you can get your own reputation from it
 
10:56 AM
oh that's nice...
... python3.7 and newest pip, pip install -e . does not read setup.py if egginfo exists.
 
does anyone know whether it's possible to refer to the precise class in a ClassVar annotation? I know it works for classmethod, but both Mypy and PyCharm hate my guts when doing it in the class body.
S = TypeVar('S')

# magic __new__ that sets __singleton__

class Singleton:
    __singleton__: 'ClassVar[Optional[S]]' = None  # ?!?

    @classmethod
    def fake_new(cls: S) -> S:  # S is the precise (inherited) class
        return cls()
 
11:14 AM
@roganjosh it might be bad from a QnA repository but from a communal welcoming POV it's very good, coding is v.hard and often people (speaking of myself first and foremost) have poor researching skills, and often don't know what to search for which is sometimes easier to ask a question. It's not a perfect model but I think in the absence of paid staff who go around cleaning the questions/closing dupes daily it works
 
thank you so much for the help btw
:)
 
on another note, I didn't think I would enjoy refactoring code so much, it's quite cathartic
 
@Datanovice The problem is that it continuously increases noise versus signal, making researching-with-poor-research-skills progressively harder. Since dupe-flagging is based on researching, that gets continuously more challenging as well.
 
@MisterMiyagi agreed, but this is a SO problem, they need to implement better solutions that the community can take up - for users we do what's easy and the gamifcation makes answering such questions instantly gratifying for our attention defunct brains
 
@Datanovice As a user spending more time answering than asking, I can assure you it's neither easy nor gratifying.
 
11:33 AM
@MisterMiyagi I dont even ask after 2-3 hour google sometimes, I believe to find, you might do the same
This actually makes my search skill on google way way more better than ever
I cant define problems way more better than ancient times
I can define*
 
Cbg everyone
 
Cgb
 
11:51 AM
@MisterMiyagi Not quite sure why you want to use a TypeVar there. Anything wrong withClassVar[Optional['Singleton']]?
actually, forget I asked, I'm a bit slow today
 
\o/
 
@AndrasDeak got there it seems ^^^
 
puptacular
 
Pineapplesome!
 
11:58 AM
anyway - gotta run for a bit - got a lunch date... rbrb for now
 
After playing around with it for a bit I've concluded that typing is still unusable
 
it's just too cool for you
@JonClements I should downvote one of your ", not " answers to make it a flush
 
12:24 PM
I have made a class called CustomerTypes and have 1 class variable for each type of customer. Example: new_customer = 'new customer', potential_customer='potential customer'. My idea is that I can import this class and use it with autocompelte feature in other places of my code. Is there a better way to do this?
 
are you trying to reimplement enums?
 
No I dont understand
Is there any way to print the fields of a class? I am using vars currently. But it works only on an instance of class. If I use vars on a class then it shows additional things like: module, doc, dict. Is there any way to just list the class variables?
 
you can't know the attributes of a class until you have an instance, so no.
if you want to know the signature of a class's constructor, then the answer is yes. Is that what you meant?
 
No, say I have a class like this:
class Cls1:
  a=10
  b=20
Then I just need to print the {a:10, b:20}
Is this possible
 
That's definitely a poor man's enum
 
enums make listing all possible values easy; iterating over an enum yields all the values
class CustomerType(enum.Enum):
    NEW = 'new'
    POTENTIAL = 'potential'

print(list(CustomerType))
# [<CustomerType.NEW: 'new'>, <CustomerType.POTENTIAL: 'potential'>]
 
Is this a full proof (safe) approach: stackoverflow.com/a/9058322/1779091 - just updated the link
 
absolutely not
that one is horrible
 
Sorry just updated the link
[a for a in attributes if not(a[0].startswith('__') and a[0].endswith('__'))]
 
12:52 PM
that one is better, but are you really sure that using Enums is not possible?
 
Ok I wil read about enums now
 
I'm having a bit of an issue with list comprehension now that you brought it up. I solved it using for loops but it's not as fancy. So, if there are sub lists in each item of the lists, and I want for instance to concatante subitem[0], subitem[3] and subitem[5] is there a way o do it? Because I keep getting errors with:

[str(x[0] +','+x[3]+'.'+x[5]) for x in full_list if len(x) > 0]
 
what error do you get?
the syntax is fine, but calling str on an expression made of strings is fishy
note that if len(x) > 0 should probably either be if x or if len(x) > 6.
 
Yes, that's the issue. Because this full_list comes from doing some stuff with selenium and there might be empty lists. That's why there's IndexError, thanks Miyagi.
 
1:22 PM
Guys a quick question maybe you have some tips. I am trying to open a 250 mb xml file and I cannot find a way to do so, all the programms I have tried crash or cannot support it. Is there a way to do so, or maybe split it into files? I know it is not directly related to python but any tips would be more than welcome!
 
2:21 PM
cbg all
Anyone use weasyprint?
 
Nope
 
Well I'm having an issue with it finding the cairoffi library. The issues and warnings I'm finding suggest that it has this issue running on 32 bit Python, but I don't have any 32 bit installations, so I've been a bit stumped.
NBD though, it's just erroring on running tests on another part of this project, which is semi-stalled, although I occasionally go add a quick proof of concept idea to it for when I go back to working on it.
Hopefully things will eventually be upgraded such that weasyprint/setuptools/pip will all work nicely together, since that's the only thing that's changed between it working and breaking.
 
2:41 PM
Hi
 
Hello
 
cbg
 
I have a question: when doing string string replacements in XML by using replacement csv file
REPLACE_FROM,REPLACE_TO
<INCOND NAME="GUI_START_AS" ODATE="****" AND_OR="A"/>,<INCOND NAME="GUI_START_AS" ODATE="****" AND_OR="O"/><INCOND NAME="GUI_START_AS" ODATE="****" AND_OR="A"/>
 
We've probably all seen your question on the main site, no need to ask it again in here
 
okay, experts please help
 
2:44 PM
Sure... If you edit your question to include an MCVE
 
okay google
 
Kevin I have made comment as I skipped in my main question
When I see the effective replacement in my target xml: <INCOND NAME="GUI_START_AS" ODATE="****" AND_OR="O"/> <INCOND NAME="GUI_START_AS" ODATE="****" AND_OR="A"/> without line break between two tags
 
I come from background of c#. Is the concept of enums different in python?
 
I, too, come from a background of C# and in my opinion enums behave pretty similarly in both languages.
 
Enums in Python try to be conceptually the same as in C-languages, though implementation bits may look somewhat different.
Also, I think Python offers a little more variety in enum features (orderable, non-orderable), whereas in C, they are mostly just glorified ints that the compiler has special support for.
 
2:51 PM
In python the class has to inherit enum. But in c# a member of class can be an enum. So I'm not confused
 
Plain old C has enums? TIL.
I really should sit down and learn C, one of these days. Rather than trying to decipher C programs as if they were hieroglyphs, like I do now
 
But since everyone knows they are ints, they sometimes do int-ish things that are a little sketchy. Mostly implicit ordering comparisons, which break when someone decides to alphabetize the enum declarations. Also array indexing with an enum. I never saw anyone do pointer arithmetic with enums, but you could...
Which I guess array indexing is a form of pointer arithmetic, and in C, is the thinnest of syntactic sugar veneers.
 
It boggled my mind when I learned that my_array[i] is functionally identical to i[my_array]
 
I was about to say that ^
 
(... Or is that a C++ exclusive feature? Whatever)
 
2:56 PM
2[a] FTW
Assuming that's also valid
 
@Kevin no, it's from the way [] and variables work in C-ish languages
 
Ok, cool
 
a[b] as I recall is pretty much *(a + b*sizeof(a[0]))
 
@AndrasDeak Let's see.
C:\Users\Kevin\Desktop>type test.c
int main(void){
    int stuff[100];
    return 2[stuff];
}
C:\Users\Kevin\Desktop>gcc test.c

C:\Users\Kevin\Desktop>
 
So then people do things like allocating an extra slice before and after an array, and stuff special values into a[-1] and a[a_len]
 
2:59 PM
Compiles with no complaints, so I guess it's fine
 
@PaulMcG great for building pascal strings!
 
@PaulMcG can you advise what you mean by enums are ints
 
Ick, that might compile, but I should think you get ACCVIO if you run that?
@variable I was referring to C, not Python.
 
@PaulMcG I ran it and nothing happened. I don't think it's an access violation. The memory belongs to me and I'm allowed to access it -- I just have no guarantees about what values it's currently holding.
 
@Kevin how optimistic ;)
 
3:02 PM
If I had done 999[stuff], maybe that would be an access violation
 
Try --stdc99 --pedantic or whatever
@Kevin read might not even cause segfault, only write
 
gcc: error: unrecognized command line option '--stdc99'; did you mean '--stdc99'?
Are my eyes broken, or are those identical
 
1589
Q: With arrays, why is it the case that a[5] == 5[a]?

DinahAs Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a] Joel says that it's because of pointer arithmetic but I still don't understand. Why does a[5] == 5[a]?

 
@variable In Python, to get int-like support, use IntEnum subclass of Enum. In Python, vanilla Enum does not imply int-ability, so it makes you do this as an overt, explicit, conscious act, not as a well-known-but-still-hackish reliance on an implementation detail.
 
gcc --std=c99 --pedantic test.c executes with no warnings
 
3:05 PM
That's much more reassuring :)
Sorry for the arg mistake, I haven't manually compiled C in 5-10 years
 
I wish C had a nice official docs site like Python has. open-std.org/JTC1/SC22/WG14/www/standards doesn't count.
 
Enum in python seems to be much like data class?
Except in enum you can iterate over the class variables.
Have I got that right?
 
@AndrasDeak Me neither, so I understand. To be clear, my unrecognized command line option message is supposed to convey "haha, look at this unhelpful error" and not "haha, Andras got the syntax slightly wrong"
 
And the variables themselves are const - in dataclasses, they are mutable, are they not? unlike namedtuples? Also, in Enum, you never actually instantiate one like you would a dataclass, you always use just the singleton class and its singleton class attribute enum values. So you can use if mycolor is Color.red, not if mycolor == Color.red
So while dataclasses and enums may have some similarity in appearance in your code, they are still pretty different creatures.
 
Enum class's variable can have the value as named tuple
We can do so many interesting things here
 
3:13 PM
I need to break off for a bit, the paying gig beckons - tl;dr rbrb
 
@PaulMcG what you mean by variable being mutable with respect to data class and named tuple please?
 
@variable If by "the class has to inherit enum" you mean "the class that defines the members of the enum has to inherit from Enum", then yes. If by "the class has to inherit enum" you mean "if a class wants to use an enum value in an attribute, it has to inherit from Enum", then no. If you have a class Apple with an attribute color, you don't have to make Apple inherit from Enum.
 
@Kevin@AndrasDeak I posted a question a while ago about reading a 250MB xml file. Do you have any ideas on how I can see its content. Currently whatever software a have tried has crashed and I am looking for perhaps some code to split it. Any ideas? I am tagging you too as you have also helped me in the past
 
The only off-the-shelf software I've used to view xml files is Notepad++. The only xml-related Python module I've used is xml.etree.ElementTree. If neither of them can read the document, I don't have any other ideas.
 
okay thank you I will try to figure it out
 
3:25 PM
@Kevin you mean to say that if value of an attribute is enum you need not inherit enum.
But to make the class an enum we need to inherit enum
Hope i got that
 
@Vasilis did you already stumble over iterparse?
 
Ugh, did I just flag Vasilis' comment? If so, please ignore. Trying to use the main view on a mobile and something screwed up on my mobile
You've mentioned twice that a 250MB file keeps crashing. Are you sure this is a memory issue?
 
why does everyone use bfs etc. whats wrong with my method?
 
3:46 PM
I don't think it makes much sense to do sample.append(item) in that else block there, since you completely overwrite the variable with a new list in the next iteration when you do sample = []
 
i think the question looks like it is given a list to the function, but in reality its not
 
I'm giving a list to your function and getting the wrong answer, so I don't think the problem is typing.
 
its ok
just an input issue i think
my idea was right
 
I can't say whether your idea is right, but I can say that the implementation is wrong
 
ok
 
4:01 PM
That said, I do find it kind of suspicious that the ostensible entry point provided for the problem takes a Node rather than a list of ints. This implies to me, either 1) the input really is a list of ints, the stub method supplied is not really the entry point, and you have to write your own entry point method that calls the stub method; or 2) the stub method really is the entry point and the problem description is lying about the format of the input.
 
yeah i know
leetcode is hard enough without input worries
 
If you have access to other people's solutions, it should be pretty easy to tell which one of these is the truth. If they all have code that turns a List<int> into a collection of Node instances, then it's #1. If they all take a node instance from somewhere without creating it themselves, then it's #2.
I don't know if you have access to other peoples' solutions. I definitely don't, but I don't have a leetcode account, and I don't know what kind of perks actual users have.
Browsing through the discussion tab, it looks like #2 is the truth. So the answer to "whats wrong with my method?" is "leetcode lied to you about the form of the input, so your code doesn't work on the real data"
 
i can see that its not a list
 
Problem solved, then. Throw away the code you've got, and write something that will work for Node instances.
 
4:13 PM
A short question: Do all fundamental operations like increment and comparision are of same cost?
More or less I define by cost as the effort that the CPU needs to expend in order to that particular job.
 
@AjayMishra By operations, do you mean Python operations (==, +, ...) or CPU operations (like float add, int32 add, ...)?
 
I guess, I mean C operations[But that won't matter]
Like +, -, ==
 
My initial thought is that comparison would be more expensive but then I realized that an increment does some comparison to see if the two things are of a type that can be incremented...
 
Depends on the language. In low level languages like assembly, simple integer operations are handled by the ALU and all take one cycle*. In Python, adding two objects might cause several functions to be called.
(*at least, that's how it works in the dumbed-down idealized architecture that was taught to me in college. Maybe it's different for actual commercial hardware?)
 
Shouldn't we consider while dealing computing the algorithmic complexity(From that I mean just computing the time taking as a function of n).
 
4:19 PM
Algorithmic complexity is explicitly divorced from concerns of "wall clock" time costs
Of course, it's a perfectly fine idea to take both complexity and wall clock time into account when designing your program
 
Okay, even if do not consider the wall clock and stuff, do these operation take same effort?
 
Short answer: no, they don't.
 
I mean to ask the fundamental defintion.
 
I'm 70% sure that adding two floats takes substantially more "effort" than adding two ints, even in C
... but I'm willing to be proven wrong on this. "Actually, modern FPUs are just as fast as ALUs thanks to quantum pipeline multicore blockchains"
 
Should I ask this on mainsite? Though I do not have enough content to specify the question I wanted to ask.
 
4:26 PM
%timeit 1 == 'a'
89.8 ns ± 50.7 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

%timeit 4 * 4
23 ns ± 8.25 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)

%timeit 4.0 * 4.0
48.7 ns ± 27.1 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)
 
Multiplying literals together might give misleading results, depending on whether timeit allows binop folding at compile time
 
I cannot speak to the process of these things which seems to be the heart of the inquiry at this point
But those times I expected
 
Perhaps timeit is smart enough not to optimize away the thing you want to measure. I tried with nonliterals and got similar results:
>>> timeit.timeit("a*b", globals={"a": 4, "b": 4})
0.26722507200000223
>>> timeit.timeit("a*b", globals={"a": 4.0, "b": 4.0})
0.3045974730000012
 
@AjayMishra Fundamental CPU operations are fundamentally fundamental. They are O(1) by construction.
 
@MisterMiyagi then I guess these are not really fundamental.
 
4:32 PM
@Dodge I cannot replicate these timings. 4 * 4, 4.0 * 4.0 and 16 all are identical within error for me.
 
@MisterMiyagi My jupyterhub server is super low budget and that's where I do IPython work so maybe that is a factor?
 
If you're saying "I guess algorithmic complexity is useless if it doesn't take into account CPU time", that's like saying "I guess the Ideal Gas Law is useless because it doesn't take into account un-ideal conditions".
 
@AjayMishra What I mean is that CPU operations don't operate on some n, so they cannot scale. The size of an operation is well-defined by the data type length and word length.
 
Or "arithmetic is useless in answering the question 'if I have one apple and my friend gives me another, how many do I have?' because it doesn't take into account the possibility that you planted the seeds from your apple and now have hundreds of apples"
 
that's very philosophic
 
4:36 PM
Hi guys I have a serious problem
T_T
 
Or maybe you're just saying "although algorithmic complexity is useful, you can't use it to derive the actual real-world runtime of a program with it", which is true.
 
Could anyone help me out?
 
yes you do. Your keyboard seems to have replaced a detailed description your problem with "T_T". That's a pretty weird problem
 
Algorithmic complexity is "not fundamental" in the sense that it's not a sufficient collection of axioms that will let you derive all true facts about the real world
 
Hmm, I initially thought that algorithmic complexity reflects the running time of the program, but when one considers these factors, it kinda feels incomplete.
 
4:37 PM
@MisterMiyagi going full circle then, you observe no difference in time... but comparisons do take more work, right?
 
@inspectorG4dget HAha
 
@Dodge yes, == isn't optimised by CPython
 
Im using webrtc to take a picture , the image is in base64, I'm using $.ajax to send a string over to my python server, how should I let my python server recognize the string is a picture ?
 
@AjayMishra algorithmic complexity is how runtime grows, not how much it is.
 
@AjayMishra Pretty much. Algorithmic complexity is just one tool in your toolbox.
 
4:39 PM
before this I was using input="file" which worked flawlessly, but now im using a new approach. which doesnt work for me.....
 
It does many useful things, but does not do everything.
 
stackoverflow.com/q/60212594/4799172 self-dupe. This is the second I've spotted today
Mmm, how could I flag that as a dupe when it has no answer on the original?
Something is awry here. They deleted the original and it's wiped the dupe votes
 
@VentusZXC If I understand your question correctly, the server can tell whether the string is a picture, if the string starts with "data:image/png;"
If the question is "given a string which I'm sure starts with "data:image/png;", how do I render it on screen and/or save it to an actual png file?", I'm not sure.
 
@Kevin the first one
Now only my server can recognize file types of jpg, png and jpeg
but not base64 image
 
Hmm, this might be a framework-specific question. What does your server tech stack look like? Are you using flask, for example?
 
4:47 PM
yeah im using flask
 
I was hoping that Flask had a built-in parser for the kind of data returned by JS' toDataURL, but poking around the documentation, I don't see anything...
stackoverflow.com/questions/42762269/… is somewhat similar to your setup, I think... The answer talks about how you can extract the base64 info from the data and decode it into the contents of a valid png file (... I think)
These kinds of question are tricky because it's so hard to compose an MCVCE :-/
Too much essential configuration data spread across half a dozen files
I don't know if this is helpful, but here's a snippet that takes the kind of data returned by toDataURL, and saves it as a valid png file
import base64

#typical data, taken from developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/…
s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAADElEQVQImWNgoBMAAABpAAFEI8ARAAAAAElFTkSuQmCC"

data = s.split(",",1)[1].encode()
with open("result.png", "wb") as file:
    file.write(base64.decodebytes(data))
 
5:36 PM
On the main site, a disagreement between asker and answerer culminates in "will you email me your code?", then "sure". I feel like this is suboptimal.
If only there were a way to host snippets of code in a publicly viewable manner
 
yeah public code repositories and snippets, could call it "bithub"
There's like four or five obvious ways to share code online but now my mind has wandered to the less obvious ways, pictures of code shared on instagram, a video of your code on youtube, hijacking the comments section of a food blog to share code...
 
Why not just make the Instagram account? Selfies with a beautifuly-constructed interface on a laptop screen with some vista behind it
 
6:07 PM
What are those external places we can copy links to here to ask a question about code?
 
I may have been too vague. The hosting site I was hinting at is Stack Overflow itself. If the asker had a problem with his code, he should have put it in his post.
 
@Pandasncode dpaste, pastebin, github (gist) regarding posting links to code here
 
6:21 PM
@Kevin if only. alas :P
I wish there was some kind of site where you could easily paste and format your code while asking questions about it.
 
wim
^ translating common python idioms such as context managers and list comprehensions into Go
 
I knew what Kevin meant but I was pointing out that beyond SO there are three or four other obvious places and probably ten more not so obvious places to post code
 
wim
(helpful for me, who sometimes uses Go when Python is too slow, maybe helpful for others?)
 
So, the Go equivalent of a list comp is... a for loop that calls .append :-I
 
Curious, is list comp style syntax even there in any other language?
 
6:24 PM
C# has linq, which has some similarities
#Python
x = [item * 2 for item in seq if item > 50]

#C sharp
x = from item in seq where item > 50 select item * 2;
 
I must admit, I might have been accidentally spoilt by python in the sense that reading append(list, item) feels wrong to me.
@Kevin nifty, thanks Kevin. I think that's decently similar
Enumerating: In Go, this is the default behavior
you know, i could dig that. Seems like a pretty decent idea to me, coupled with the _ variable name as a "throwaway" convention ofcourse
 
wim
listcomps were in smalltalk (70s) and I'd wager maybe even in some 60's languages
 
I would not hate to live in the alternate universe where iteration yields both keys and values by default
 
@Kevin I love it when you talk dirty
 
The FPU also uses The Cloud, but very quickly
 
7:12 PM
@Kevin yeah, I got that
 
👍
 
@roganjosh self-dupe is an explicit exception
 
@PaulMcG I'm looking at the tests in plusminus, I can't find where runTests is defined?
 
I've been talking in here for a couple of days about my issues..... but really trying to just find it myself. I should have just posted it.... I was spelling ledgend not legend..... <<< the entire problem that I destroyed hundreds of lines of code for to rebuild.... Thanks anyone that replied to me during this time.
 
@Pandasncode you probably didn't post the error message then
At least you've found it eventually :)
 
7:19 PM
No. I think I may have just been asking general questions because I thought my lists were empty from other outputs I was getting. I was really trying to figure it out on my own. Be self sufficient.
 
That's a great attitude, but if you're new to debugging or the language some quick pointers go a long way
 
They do! I do not disagree. I'll just ask next time so someone can point out that I can't spell. Laurel.
 
The nice thing about MCVEs is that creating one is useful for both 1) seeking help from others; or 2) trying to solve the problem on your own
 
We're actually very happy to help askers who are recipient to suggestions :)
 
Also, it's good to get some "facepalm" moments out of your system, the earlier the better. They happen to everyone, far more often than you'd think
(or maybe that's just me. hmm)
 
7:25 PM
I will definitely be asking in the future. I'm just glad it's done. I was definitely at the "end of the world burning office around me" scenario in my head going "this is fine!"
 
@AndrasDeak that's... <takes a breath> a nice feature :) I didn't know that
 
@toonarmycaptain The ArithmeticEvaluator __getattr__ forwards that call to its captive pyparsing ParserElement parser. Here are the online docs for runTests: pyparsing-docs.readthedocs.io/en/pyparsing_2.4.6/…
I'll eventually convert these to actual unittest tests - runTests can be automated to validate its results, but its kind of a pain and I just usually eyeball the output. But runTests is nice for quick "here's a bunch of crazy test inputs I just thought up and want to run them even if they don't all work" testing.
Or dare I say, write the code for the runTests call and test strings before writing the parser... ?
 
@PaulMcG Oh ok. What sort of CI were you looking at setting up? I was looking at rewriting that script as more recognisable unittests or Pytests, depending on what sort of CI you wanted to implement. But the I couldn't see runTests anywhere in the repo, so.
 
I'd prefer unittest, even though pytest is the hotness now.
Might be worth importing pyparsing.pyparsing_test to get the new pyparsing-friendly unittest asserts.
Probably will just use TravisCI again.
 
7:40 PM
dupe lexical sort vs numerical sort.
 
Hello, I know this is more meta SO, and not too python related, but is there a way to flag an edit?
 
@CeliusStingher what do you want to flag about it?
either way the only choice is a custom mod flag, but this might be an XY problem
 
Editor removed relevant tags and expected output
stackoverflow.com/questions/60215155/… in case anyone wants to check it out
 
If you think it was just a mistake we can roll back. If you think there's something fishy going on it's better to alert the mods.
@CeliusStingher yeah, thanks, I was about to ask
 
I think it has been cleared in the comments now, it's good to know for a future occasion :) melons
 
7:46 PM
@CeliusStingher martineau edits a lot of things, I'm pretty sure they just made a mistake. I think their edit got its wires crossed with yours
 
Yep, that's why I asked him in the comments before flagging anything :)
 
yeah, assume good faith
 
The edit history is messy. But why does the OP have a list in a column in the first place?
 
plenty of people have a list in a column, alas
@CeliusStingher I've found the issue: both martineau and you chose "improve edit" in the review stackoverflow.com/review/suggested-edits/25349814, so both of you started from the same suggested edit and modified it in a way that diverged
 
I really wish I had some insight in what has come before. As it is, I can't apply intuition to stop this being a thing :(
 
7:54 PM
I sometimes end up pivoting tables and using, with strings as values and aggregation (list). I think that's the main reason I end up with lists in a not-so-wrong-way-of doing-things way
 
puts cotton in ears na na na can't hear you blasphemy lists in columns take that! snaps fingers in the air
 
I just glanced over and saw "SQL injection" on the star board, but read "SQL infection".
 
well it's not wrong
 
@PaulMcG corona-shmora virus. If SO is to believed as representative, we're screwed
 
@PaulMcG I'll have a look at these and see what I come up with. I haven't used Unittest in ages!
 
8:07 PM
Look at the test_unit.py file in the pyparsing repo. Once you get the pattern down, it's easy enough.
I actually prefer the assertXXX methods in unittest vs. just assert whatever with pytest.
Coronavirus case reported just an hour away in San Antonio. I think I'll just wfh for the next year.
 
@PaulMcG There's more specificity there I guess. I like how the reusable fixtures and parametrization work, and what I find as much more readable pytest, without the boilerplate unittest involves.
 
wim
8:23 PM
@PaulMcG get out!
 
Well, I'm willing to (shudder) learn, if there are pytest analogues to the assertXXX functions I added to pyparsing that would be doubleplusgood. But I quibble with just how much boilerplate unittest involves - is inheriting from a TestCase class so awful?
 
wim
yes. go back to java if you like TestCase :D
regarding the pytest analogues to custom assertThing functions, yes, it's registering an assert rewrite
 
"go back to java" - smiley or no, words can hurt
Ok, I have recovered
 
wim
if ast rewrites seems too magical, you can also just use a plain old function
def assert_thing_is_length_42(thing):
    if len(thing) != 42:
        pytest.fail("your custom failure message here")
IMO pytest is much more pythonic, the java world of "everything must be a class, every function is a method" does not jibe well in Python
 
Ok then, @toonarmycaptain go ahead and do your work with pytest instead of unittest, and I'll gladly wipe some more of the J-language off the bottoms of my shoes (along with Py2).
 
8:38 PM
@PaulMcG It's the setup and teardown I'm referring to. In pytest I could setup a parser with whatever one wanted, stick that in a fixture, and just inherit that fixture for each test.
 
Every test framework is going to have something like that, whether it is a setup() method or a reused fixture thing.

You guys have said enough on the subject, I'll go watch a pytest tutorial.
 
wim
Yes every test framework should have this basic feature, how nicely it's implemented depends on the framework :)
pytest fixtures are very similar to contextlib.contextmanager. everything that happens before the yield statement is analogous to a TestCase setUp method, everything after the yield statement is the tearDown
this ends up being nicer and more reusable when you have multiple things to setup teardown, because in unittest you can end up in inheritance hell trying to write mixin classes that are not actually test cases, and wrestling with the MRO
but with pytest fixtures, you just "inject" them in the same order you want the contexts entered (and they are exited in reverse order)
the actual object yielded in the yield statement, if any, is the object which is bound to the fixture name within the test. often it's a mock, but in general it can be any python object of course.
 
06:00 - 21:0021:00 - 00:00

« first day (3407 days earlier)      last day (1540 days later) »