tagged [python]

Converting string to tuple without splitting characters

Converting string to tuple without splitting characters I am striving to convert a string to a tuple without splitting the characters of the string in the process. Can somebody suggest an easy method ...

How to print like printf in Python3?

How to print like printf in Python3? In Python 2 I used: I've tried:

2 Aug at 20:0

How to read numbers from file in Python?

How to read numbers from file in Python? I'd like to read numbers from file into two dimensional array. File contents: - - For example:

21 Sep at 19:15

Python: OSError: [Errno 2] No such file or directory: ''

Python: OSError: [Errno 2] No such file or directory: '' I have a 100 lines, 3 years old python scraper that now bug. Starting lines are: When run, I recei

31 Mar at 01:14

How do I get a decimal value when using the division operator in Python?

How do I get a decimal value when using the division operator in Python? For example, the standard division symbol '/' rounds to zero: However, I want it to return 0.04. What do I use?

How to run multiple functions at the same time?

How to run multiple functions at the same time? I'm trying to run 2 functions at the same time. Does anyone know how to do this?

Correct way to try/except using Python requests module?

Correct way to try/except using Python requests module? Is this correct? Is there a better way to structure this? Will this cover all my bases?

How do I make function decorators and chain them together?

How do I make function decorators and chain them together? How do I make two decorators in Python that would do the following? Calling `say()` should return:

Command line input in Python

Command line input in Python Is it possible to run first the program then wait for the input of the user in command line. e.g.

Extracting text from a PDF file using PDFMiner in python?

Extracting text from a PDF file using PDFMiner in python? I am looking for documentation examples on how to extract text from a PDF file using PDFMiner with Python. It looks like PDFMiner updated thei...

How can I check for a new line in string in Python 3.x?

How can I check for a new line in string in Python 3.x? How to check for a new line in a string? Does python3.x have anything similar to java's regular operation where direct `if (x=='*\n')` would hav...

4 Mar at 12:59

How to send a "multipart/form-data" with requests in python?

How to send a "multipart/form-data" with requests in python? How to send a `multipart/form-data` with `requests` in python? How to send a file, I understand, but how to send the form data by this meth...

How to convert string to binary?

How to convert string to binary? I am in need of a way to get the binary representation of a string in python. e.g. Is there a module of some neat way of doing this?

3 Oct at 21:5

How to crop an image using PIL?

How to crop an image using PIL? I want to crop image in the way by removing first 30 rows and last 30 rows from the given image. I have searched but did not get the exact solution. Does somebody have ...

22 May at 09:13

How to get method parameter names?

How to get method parameter names? Given that a function `a_method` has been defined like Starting from `a_method` itself, how can I get the argument names - for example, as a tuple of strings, like `...

Any way to clear python's IDLE window?

Any way to clear python's IDLE window? I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear pyth...

19 Apr at 00:42

What is sys.maxint in Python 3?

What is sys.maxint in Python 3? I've been trying to find out how to represent a maximum integer, and I've read to use `"sys.maxint"`. However, in Python 3 when I call it I get:

18 Apr at 20:6

Upgrade to python 3.8 using conda

Upgrade to python 3.8 using conda Python 3.8.0 is out, but I haven't been able to find any post on how to update to python 3.8 using conda - maybe they will wait for the official release? Any suggesti...

26 Oct at 04:55

Converting dictionary to JSON

Converting dictionary to JSON I am not able to access my data in the JSON. What am I doing wrong?

28 May at 17:15

requests: how to disable / bypass proxy

requests: how to disable / bypass proxy I am getting an url with: As I can see in the 'access.log' of "myserver.com", the client's system proxy is used. But I want to disable using proxies at all with...

24 Aug at 15:22

How to get the domain name of my site within a Django template?

How to get the domain name of my site within a Django template? How do I get the domain name of my current site from within a Django template? I've tried looking in the tag and filters but nothing the...

Generate a random letter in Python

Generate a random letter in Python Is there a way to generate random letters in Python (like random.randint but for letters)? The range functionality of random.randint would be nice but having a gener...

17 Jun at 13:39

Why should we NOT use sys.setdefaultencoding("utf-8") in a py script?

Why should we NOT use sys.setdefaultencoding("utf-8") in a py script? I have seen few py scripts which use this at the top of the script. In what cases one should use it?

15 Nov at 22:3

`from ... import` vs `import .`

`from ... import` vs `import .` I'm wondering if there's any difference between the code fragment and the fragment or if they are interchangeable. If they are interchangeable, which is the "standard"/...

Is there a ceiling equivalent of // operator in Python?

Is there a ceiling equivalent of // operator in Python? I found out about the `//` operator in Python which in Python 3 does division with floor. Is there an operator which divides with ceil instead? ...

2 Jul at 12:59

TypeError: worker() takes 0 positional arguments but 1 was given

TypeError: worker() takes 0 positional arguments but 1 was given I'm trying to implement a subclass and it throws the error: `TypeError: worker() takes 0 positional arguments but 1 was given` ``` clas...

19 Sep at 01:23

Unzipping files in Python

Unzipping files in Python I read through the [zipfile documentation](https://docs.python.org/3/library/zipfile.html), but couldn't understand how to a file, only how to zip a file. How do I unzip all ...

1 May at 12:27

What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?

What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python? When I try to use a `print` statement in Python, it gives me this error: What does that mean?

5 Jun at 16:27

python mpl_toolkits installation issue

python mpl_toolkits installation issue After command `pip install mpl_toolkits` I receive next error: > Could not find a version that satisfies the requirement mpl_toolkits (from versions: )No matchin...

28 Dec at 02:24

TypeError: 'module' object is not callable

TypeError: 'module' object is not callable Why am I getting this error? I'm confused. How can I solve this error?

I can't install python-ldap

I can't install python-ldap When I run the following command: I get this error: > In file included from Modules/LDAPObject.c:9:Modules/errors.h:8: fatal error: lber.h: No such file or directory Any id...

21 Jul at 14:17

What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc?

What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc? Python 3.3 includes in its standard library the new package `venv`. What does it do, and how does it dif...

How to upgrade Python version to 3.7?

How to upgrade Python version to 3.7? I have python3.5 already in linux ubuntu. I have downloaded the python3.7.tar [www.python.org](http://www.python.org). But i have no idea how to install it. How t...

11 Jul at 07:40

How to avoid "Permission denied" when using pip with virtualenv

How to avoid "Permission denied" when using pip with virtualenv I attempt to deploy a Python package with `pip` in a virtual environment on an Ubuntu machine, but encounter a permission-related issue....

How can I use threading in Python?

How can I use threading in Python? I am trying to understand threading in Python. I've looked at the documentation and examples, but quite frankly, many examples are overly sophisticated and I'm havin...

Importing files from different folder

Importing files from different folder I have this folder structure: How can I import a function from `file.py`, from within `some_file.py`? I tried: but it doesn't work.

28 Aug at 02:26

Explain the "setUp" and "tearDown" Python methods used in test cases

Explain the "setUp" and "tearDown" Python methods used in test cases Can anyone explain the use of Python's `setUp` and `tearDown` methods while writing test cases apart from that `setUp` is called im...

20 Feb at 11:43

Convert string to variable name in python

Convert string to variable name in python I have any string. like 'buffalo', I want to convert this string to some variable name like, not only this example, I want to convert any input string to some...

20 Feb at 15:8

How to write PNG image to string with the PIL?

How to write PNG image to string with the PIL? I have generated an image using [PIL](http://www.pythonware.com/products/pil/). How can I save it to a string in memory? The `Image.save()` method requir...

29 May at 16:30

How to load a C# dll in python?

How to load a C# dll in python? how can I load a c# dll in python? Do I have to put some extra code in the c# files? (like export in c++ files) I don't want to use IronPython. I want to import a modul...

7 Sep at 20:27

Get exception description and stack trace which caused an exception, all as a string

Get exception description and stack trace which caused an exception, all as a string How to convert a caught `Exception` (its description and stack trace) into a `str` for external use?

How to print variables without spaces between values

How to print variables without spaces between values I would like to know how to remove additional spaces when I print something. Like when I do: The output will be: But I want: Is there any way to do...

23 Feb at 09:45

How would I stop a while loop after n amount of time?

How would I stop a while loop after n amount of time? how would I stop a while loop after 5 minutes if it does not achieve what I want it to achieve. This code throws me in an endless loop.

23 Mar at 20:15

Difference between os.getenv and os.environ.get

Difference between os.getenv and os.environ.get Is there any difference at all between both approaches? They seem to have the exact same functionality.

How to sort a dataFrame in python pandas by two or more columns?

How to sort a dataFrame in python pandas by two or more columns? Suppose I have a dataframe with columns `a`, `b` and `c`, I want to sort the dataframe by column `b` in ascending order, and by column ...

How do I create test and train samples from one dataframe with pandas?

How do I create test and train samples from one dataframe with pandas? I have a fairly large dataset in the form of a dataframe and I was wondering how I would be able to split the dataframe into two ...

10 Jun at 17:24

What is the best way to remove accents (normalize) in a Python unicode string?

What is the best way to remove accents (normalize) in a Python unicode string? I have a Unicode string in Python, and I would like to remove all the accents (diacritics). I found on the web an elegant...

EOFError: EOF when reading a line

EOFError: EOF when reading a line I am trying to define a function to make the perimeter of a rectangle. Here is the code: I think I haven't left any arguments opened or anything like that.

16 Jul at 11:56

Extract Number from String in Python

Extract Number from String in Python I am new to `Python` and I have a String, I want to extract the numbers from the string. For example: Output is `['4', '3']` I want to get `3158` only, as an Integ...

2 Nov at 18:11

pip install returning invalid syntax

pip install returning invalid syntax I've just installed python 3.6 which comes with pip However, in Windows command prompt, when I do: 'pip install bs4' it returns 'SyntaxError: invalid syntax' under...

4 Dec at 12:11