I want to split the string into integers and operators for doing Infix expression evaluation in python. Here is my string: I tried this to split: This is wrong. Since ’10’ is splitted into ‘1’,’0′ I tried alternative: This is also went wrong. Since ‘)*’ should b…
Tag: python
Python win32com constants
I’m currently wondering how to list the constants in win32com in python, for example using excel win32com.client.Dispatch(‘Excel.Application’) Is there a way to display all constants using win32com.client.Constants ? Or does someone know where i could find win32com’s documentation ? Be…
Getting the name of a variable as a string
I already read How to get a function name as a string?. How can I do the same for a variable? As opposed to functions, Python variables do not have the __name__ attribute. In other words, if I have a variable such as: I am looking for a function/attribute, e.g. retrieve_name() in order to create a DataFrame i…
Print range of numbers on same line
Using python I want to print a range of numbers on the same line. how can I do this using python, I can do it using C by not adding n, but how can I do it using python. I am trying to get this result. Answer Python 2 Python 3
“set session” in a SQLAlchemy session object
I’m using SQLAlchemy for a project, and need to be able to specify a session variable/setting for one specific call for performance reasons: I can of course do this in MySQL directly (on the shell), but how do I set this session variable in a SQLAlchemy session? Answer Use a session event to execute an …
Tkinter importing without *?
In my past programming i used the following code: but someone told me that importing * was not good for many reasons but now when i want to import it says geometry not a module thing (name). and when i do: it says ‘module’ object has no attribute ‘geometry’ Can someone explain me how t…
Saving UTF-8 texts with json.dumps as UTF-8, not as a u escape sequence
Sample code (in a REPL): Output: The problem: it’s not human readable. My (smart) users want to verify or even edit text files with JSON dumps (and I’d rather not use XML). Is there a way to serialize objects into UTF-8 JSON strings (instead of uXXXX)? Answer Use the ensure_ascii=False switch to json.du…
How to upload a file using an ajax call in flask
Hi I’m quite new to flask and I want to upload a file using an ajax call to the server. As mentioned in the documentation, I added a file upload to the html as folows: and I wrote the ajax handler as this I do not know how to get the uploaded file (not the name) from this and save
Referring to variables of a function outside the function
The result is: NameError: name ‘a’ is not defined Is it possible to use a outside the function? Answer In python the scope is a function, or class body, or module; whenever you have the assignment statement foo = bar, it creates a new variable (name) in the scope where the assignment statement is …
What’s the best way to generate random strings of a specific length in Python?
For a project, I need a method of creating thousands of random strings while keeping collisions low. I’m looking for them to be only 12 characters long and uppercase only. Any suggestions? Answer CODE: OUTPUT: 5 examples: EDIT: If you need only digits, use the digits constant instead of the ascii_upperc…