Stupid question here, but is there a specific name for the variable generated from a loop? As in the i in for i in range(10), do we just call that a variable?
In languages where for loops are constructed similarly to this:
for (int i = 0; i < max; i++) {}
the variable i in this example seems generally to be referred to as a "counter variable".
What is the equivalent technical name for the loop variable in Python, where for loops are more like for e...
That answer really sent me down a rabbit hole becuase now I'm wondering if you can define the target list in a way that would make the loop variable change everytime, which would be completely useless in any real sense... I think target list is a misleading term
Well, it lasted longer than I dared hope when I decided to post it
Any opinions on what I should do with the question? On one hand I'd like to keep to keep it because some people might find the answer I posted useful or because I might get some feedback from people who disagree and learn something from it. On the other hand, it's unfair that I'm the only one with an answer on the question
Not sure what you mean. There are no interfaces in python, and it's easy to prove that object is not abstract or a metaclass
>>> object() # not abstract
<object object at 0x7f13bb9bb0d0>
>>> class Foo(metaclass=object): pass # not a metaclass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object() takes no arguments
@Phil Try total_pages, page_counter, scroll_size, page = iter. Also, iter isn't the best variable name of all times because it shadows the builtin iter.
@fstab Okay, I guess you're right. But please include a Minimal, Complete, and Verifiable Example in your question next time; that could've avoided this unproductive discussion
hey guys I am debugging some python code in eclipse with PyDev plugin. I get a lot of PyDev plugin debug logs in eclipse console of the form pydev debugger: warning:. How do I prevent them from appearing in the eclipse console?
I seem to have trouble communicating my super woes to other people, so if anyone can be bothered to read a wall of text I'd appreciate some feedback on my new question about super. What can I do to make it clearer? What's making it confusing?
what's currently the most precise platform independent way to measure performance? In this thread stackoverflow.com/questions/7370801/… they introduce native time.time(), time.clock() and 3rd party timeit and datetime
@Aran-Fey I think that's the case, and it doesn't seem sarcastic. That's why I felt it was funny. The question is more complex than a basic inheritance tutorial.
You should see the answer that person posted. One version didn't call the Foo constructor, and the other version didn't call either one of the two parent constructors
I think Andras / PM2Ring had 2.6 somewhere on their computer, no idea about online interpreters, but likely think that they won't exist. Unless you get hang of some ancient servers.
Historically PM has been very helpful in answering my 2.6 related queries but all programmers know that the best workflow is one that doesn't involve any other humans
I guess so. But I might have problems with OpenSSL. I might have to compile that as well, or at least manually download the .deb. I can't upgrade it with apt-get
Hi! does anyone here know about a good list of standardized log parses for different systems in python (nginx,apache,linux logs, squid,postfix etc...) ?
* = something like this: https://github.com/etsy/logster/blob/master/docs/parsers.md But with more parsers, specifically in python.
Am I wrong in understanding that they started their answer saying that there is another scenario the accepted answer illustrates, which they try to portray, but in the end showcase the exact scenario that they were not trying to show?
I mean, if it helps add another explanation, I'm all for it. If ultimately their scenario complements it well, it probably needs to just be edited to provide an additional scenario rather than make it look like it is contrary to my example
I think he's saying "the problem might not be evident just by looking through the code of the main source file of your project".
Consider a file myproject.py which has import mydecimal, and mydecimal.py which has import decimal, and a local decimal.py file. Running myproject.py will cause an AttributeError, but just looking at the contents of myproject.py will not tell you that decimal is being overshadowed
I think this is effectively what that user is saying, but they didn't explicitly mention that you're not running mydecimal.py directly
On my third read, no, that's not it
He's saying "import decimal can fail even if you don't have any local files named decimal.py. You can get an AttributeError by overshadowing a module that never appears in any import statement in your project"
The accepted answer advises checking the traceback, but this advice is not globally applicable. Dave Rose's traceback contains no hints that numbers.py is the file that's causing the overshadowing. (although maybe you can guess since it mentions Number, and where else but numbers.py would such a thing be defined)
Although I notice on my machine, the error message is AttributeError: module 'numbers' has no attribute 'Number', which does give you a hint to what file is being overshadowed. So maybe this is less of a problem on a modern install
A decimal separator is a symbol used to separate the integer part from the fractional part of a number written in decimal form.
Different countries officially designate different symbols for the decimal separator. The choice of symbol for the decimal separator also affects the choice of symbol for the thousands separator used in digit grouping, so the latter is also treated in this article.
Any such symbol can be called a decimal mark, decimal marker or decimal sign. But symbol-specific names are also used; decimal point and decimal comma refer to an (either baseline or middle) dot and comm...
TLDR: If you use a period as a thousands separator, then you use a comma as a decimal separator.
> In the Middle Ages, before printing, a bar ( ¯ ) over the units digit was used to separate the integral part of a number from its fractional part, e.g. 9995 (meaning, 99.95 in decimal point format)
Yes, that's the one I meant. I don't see any bars above the 9995.
I suspect Wikipedia is using markup trickery to render that bar, and it's not present "inline" like the one in the parens is. The markup for the page shows that the number is 9{{overline|9}}95
Whereas the one in the parens is simply ( ¯ )
The page source for that number is <span style="text-decoration:overline;">9</span>
New topic. Today I have been tasked with implementing unit tests for the SplineReticulator web site. In order to do this, I must import code from the web site project into the unit test project. But web site project can't be imported. Therefore, I am doomed.
"You have several other web projects, right? Surely you can just look at existing unit test suites for those other projects and see how they work around this", you say hypothetically. Oh you sweet summer child.
"A well-designed solution would ensure that the web site project contains only the absolute minimum amount of executable code. If there is a substantial amount of business logic in a web site project, something has gone horribly wrong", you say. Dear reader, you are correct on all points.
web site projects should contain, primarily, resources that are not directly compiled. template files, resources such as images, etc. The actual source code should be written in a separate project, which is then imported by the web site project.
I feel bad for that question asking how to find all their API since their lead dev left, But then I guess this is why you should document all your End points.
You can jam all your source code into the web site project, and this works just fine, except that code is inaccessible by any other project. This is almost never a problem because almost no other projects would be interested in the code designed specifically for one web site.
But, oops, the unit testing project is interested in that code.
Or maybe it's wrong to say that a web site project should contain no code. .aspx files always have an accompanying source file, and you can't(?) cleanly place those into a separate project. Maybe the ideal is that the web site project should contain only code that you don't want to unit test
You would prefer selenium-style testing for code whose only visible effect is changing how a web page is rendered. So if your web site project contains all and only that kind of code, you can happily ignore it in your unit tests.
The upside is that the code that needs to be unit tested is the easiest to refactor into a separate project
I think the OP's assumption (that the accumulator value from cv2.HoughLines() can be returned) in this post may be wrong. Can't find anything supporting except a vague reference in the docstring.
In OpenCV 3.4.2 the option to return the number of votes (accumulator value) for each line returned by HoughLines() was added. In python this seems to be supported as well as read in the python docstring of my OpenCV installation:
"Each line is represented by a 2 or 3 element vector (ρ, θ) o...
I love finding a question that has already been answered and forgotten then spending too much time writing another answer that no one else will care about but me.
Poll: When implementing a file-like object, how important is it to correctly implement the read(maxsize) method? Would anyone care if I my file object returned more than maxsize bytes?
Any Flask wizards about? I'm having difficulty wrapping my head around making modular components.. I'm trying to create an authentication module which contains a User model.. I'm not really sure how I add this model into my migrate
Answered a question but a comment from the OP five minutes before my submission implies that he's stepped away from the computer to think about the problem in quiet seclusion. Bad timing.
In a month's time he'll emerge from his contemplation zone (most likely a cabin deep in the forest) and come back to my post and say "well, yeah, I figured that much out". It would save him a lot of time if he skipped all that and just gave me an accept
oh btw DSM/Idjaw, did you guys hear the Habs' GM wants to win the cup this year? not even trying to rebuild or what not, just straight up win it with the current team. I found it kinda amusing
could this pseudocode be implemented? if so, would there be a use for it, i mean when do we need a bunch of variables be created? pastebin.com/zyjm4nX1
The use would be anytime you needed something like a dictionary, so there are lots of use cases. But we just use a dictionary instead rather than cluttering up the namespace directly.
I mean, after you create the variables you need some way to treat them as a group again anyway.
@Null The conventional wisdom is that you virtually never need a variable number of variables. That's what lists and dicts are for.
You are basically doing this, but with less pleasant syntax:
def variablenames(n):
a = {}
for x in range(n):
a[n] = 42
return a
print(variablenames(3))
"But now you can't access those variables by referring to a_1, a_2, etc. You need those unsightly square brackets. Doesn't that make it worse?" you ask. Maybe. But I struggle to think of a situation where you would create a variable number of variables, but then only refer to them by literal name.
If you know you're only ever going to refer to a_1 and a_2 and a_3 and that's it, you may as well create them normally. If you don't know how many variables you need at compile time, you're going to have to do a_(n) anyway, so your code will be just as unsightly as if you had used a dictionary, if not more so
This is a rather long-winded way of saying "I agree with DSM"
Whenever I write something that contains no new information over what someone else already posted, I console myself by imagining that the intended audience still finds it illuminating thanks to the slightly different wording
Consider: a floodlight in the darkness casts many impenetrable shadows, but two floodlights may cover one another's blind spots
inb4 "bold of you to compare yourself to anything more incandescent than a glowstick"
the real problem is when you need to access anything programmatically, and your only choice is eval(f'variable_number_{k:02d}')
(I know locals() and whatnot :P)
also recbg
With lists and dicts I fail to see why many people are drawn to dynamic variable names in python. At least in MATLAB there's neither (sort of), so the replacement is non-trivial
I want to see a play written in the style of a Socratic dialogue between Simplicio, who has just come up with this great idea for variable variables, and Sophisticus, who praises the idea yet probes for technical details until Simplicio realizes that his new feature is no more powerful or concise than a dictionary
Hmm. What would you say to a proponent of variable variables who puts forth this use case: "I have a dictionary of constant values, {"inches_per_foot": 12, "feet_per_mile": 5280, "pints_per_gallon": 8, ...}. I wish to use these values in my code, but I would prefer to access them like x = y * inches_per_foot rather than x = y * constants["inches_per_foot"]."
"I never need to access the values dynamically, so I won't have to touch globals() or locals() once the names are initially injected into my scope."
What advice would you give this person? "Using a dict is so much more consise" is not as objectively true in this scenario as it is in the typical use case. If these values are used enough times, then the variable variable approach will require fewer keystrokes than the dictionary approach. And all the ugliness of the variable variables approach is concentrated in the one bit of code that injects the names, which is more easily ignored than sprinkling dict indexing everywhere
Perhaps the proper retort is "if the dict is constant, delete it entirely and manually create those variables instead. Then you save keystrokes because inches_per_foot = 12 is two fewer keystrokes than "inches_per_foot: 12", and we're not even counting the length of the name injection code"
One way would be to bfill, which makes everything before the last non-NaN value non-NaN, and then use where to select the ffill() results:
In [45]: df.ffill().where(df.bfill().notnull())
Out[45]:
date ERICB SS Equity DCI US Equity FLEX US Equity
0 2008-02-14 8.026 ...
Update: The OP from before said my answer was interesting and he would think about it. I guess he'll need to spend a month in the contemplation cabin anyway. I get that.
TIL you can use an empty Tuple as a key, guess that make sense since tuples are immutable and hashable. I guess I just never thought of using tuples as keys...
Actually digging back to my high school days, past me did use tuples as keys for my text based adventure game.... guess present me needs to remember/learn from past me...
@wim interesting, could you expand a bit more? You mean that it's better to have d[(0,1)] with d = {(0,1):1,...} than having to access d[0][1] with d={0:{1:1},...} right?
I wasn't planning to, but if it nets me a good answer...
Though it's currently sitting at a score of -1, so I should probably try to improve it before I post a bounty (though I don't really know what's wrong with it)
Alright, time to haggle. I don't think that question is worth a 500 rep bounty. Unless it's more broad than I realize, 200-300 should be plenty. How does that sound?
This was years and years ago, so don't trust my memory, but I think so -- my flight would have been late afternoon. I remember telling my father (who would have been picking me up in Calgary) about the story and why I didn't volunteer because of the inconvenience to him, and he was like "for that amount of money I'd have gotten over waiting a few hours, you should have done it". But this was pre-cellphone, so it was harder to arrange things like this..
I don't object to anything. I'm basically asking what the correct way to do it is. If your answer says "Use **kwargs in your classes because <insert explanation here>", that's a perfectly good answer
Just be prepared to answer some follow-up questions, like "Since 99% of classes I've seen don't use **kwargs in their constructor, does that mean 99% of python classes are implemented incorrectly?"
well my suggestion would be not to call super in a superCls that has a diamond shape dependency , but i understand this might be for educational purposes or your hands might be tied on this matter
im not saying don't use **args, I'm just simply saying that if you have a class that is dependent on it's super / mro might as well have a **arg so it can handle these scenario
similar example could be like I tell you to find someone to paint my room but I don't give you the price of the cost. and you don't pass that along to the next person, would be unreasonable