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.
not, anything like that, just from flask import Flask, flash, request, redirect, url_for, send_from_directory from werkzeug.utils import secure_filename
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 "
@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
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"
@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?
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.
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
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
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()
@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
@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
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?
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?
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]
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.
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!
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.
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
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.
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.
@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.
As 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.
@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.
@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.
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 = []
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.
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"
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?)
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"
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.
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.
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 ?
@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.
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))
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...
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.
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
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.
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.
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!"
@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.
@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 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
@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.
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?
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).
@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.
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.