tagged [python]

How to install mechanize for Python 2.7?

How to install mechanize for Python 2.7? I saved mechanize in my Python 2.7 directory. But when I type `import mechanize` into the Python shell, I get an error message that reads:

14 Feb at 20:8

Writing to CSV with Python adds blank lines

Writing to CSV with Python adds blank lines I am trying to write to CSV file but there are blank rows in between. How can I remove the blank rows?

28 Mar at 22:33

Python os.path.join() on a list

Python os.path.join() on a list I can do But, when I do What am I missing here?

23 Feb at 13:11

How to print an exception in Python 3?

How to print an exception in Python 3? Right now, I catch the exception in the `except Exception:` clause, and do `print(exception)`. The result provides no information since it always prints ``. I kn...

How to integrate Python Code with C#.Net Core language?

How to integrate Python Code with C#.Net Core language? Am trying to integrate python code in my .net core application for data analysis and some machine learning classification. How can I do this the...

10 Sep at 22:52

How do I unload (reload) a Python module?

How do I unload (reload) a Python module? I have a long-running Python server and would like to be able to upgrade a service without restarting the server. What's the best way do do this? ``` if foo.p...

14 Jun at 06:4

Timeout on a function call

Timeout on a function call I'm calling a function in Python which I know may stall and force me to restart the script. How do I call the function or what do I wrap it in so that if it takes longer tha...

Python, HTTPS GET with basic authentication

Python, HTTPS GET with basic authentication Im trying to do a HTTPS GET with basic authentication using python. Im very new to python and the guides seem to use diffrent librarys to do things. (http.c...

9 Aug at 16:31

Python Image Library fails with message "decoder JPEG not available" - PIL

Python Image Library fails with message "decoder JPEG not available" - PIL PIL does support JPEG in my system. Whenever I do an upload, my code is failing with: How can I resolve this?

17 Oct at 20:32

How to get tkinter canvas to dynamically resize to window width?

How to get tkinter canvas to dynamically resize to window width? I need to get a canvas in tkinter to set its width to the width of the window, and then dynamically re-size the canvas when the user ma...

How to fix "could not find or load the Qt platform plugin windows" while using Matplotlib in PyCharm

How to fix "could not find or load the Qt platform plugin windows" while using Matplotlib in PyCharm I am getting the error "could not find or load the Qt platform plugin windows" while using matplotl...

11 Jun at 16:55

update to python 3.7 using anaconda

update to python 3.7 using anaconda [Python 3.7](https://docs.python.org/3.7/whatsnew/3.7.html) alpha version is out, but I haven't been able to find any post on how to update to python 3.7 using Anac...

10 Jan at 15:38

Get all object attributes in Python?

Get all object attributes in Python? Is there a way to get attributes/methods/fields/etc. of an object in Python? `vars()` is to what I want, but it doesn't work unless an object has a `__dict__`, whi...

30 Jul at 23:3

Python Checking a string's first and last character

Python Checking a string's first and last character can anyone please explain what is wrong with this code? The output I got is: but I expected it to print `hi` instead.

17 Mar at 15:2

Add pygame module in PyCharm IDE

Add pygame module in PyCharm IDE I've downloaded `pygame-1.9.1release.tar.gz` from the Pygame website. I extracted and installed it and it's working fine in the command line Python interpreter in Term...

How to fix AttributeError: partially initialized module?

How to fix AttributeError: partially initialized module? I am trying to run my script but keep getting this error: How can I fix it?

4 Jan at 14:9

How to do relative imports in Python?

How to do relative imports in Python? Imagine this directory structure: I'm coding `mod1`, and I need to import something from `mod2`. How should I do it? I tried `from ..sub2 import mod2` but I'm ge...

16 Feb at 15:34

How do I type hint a method with the type of the enclosing class?

How do I type hint a method with the type of the enclosing class? I have the following code in Python 3: But my editor (PyCharm) says that the reference `Position` can not be resolv

Updating Python on Mac

Updating Python on Mac I wanted to update my python 2.6.1 to 3.x on mac but I was wondering if it's possible to do it using the terminal or I have to download the installer from python website? I am a...

22 Jul at 21:13

string encoding and decoding?

string encoding and decoding? Here are my attempts with error messages. What am I doing wrong? > UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 37: ordinal not in range(...

15 Oct at 10:48

How to upgrade pip3?

How to upgrade pip3? I want to use python3.5 for development, but many times when I install the module for python 3.5, it always fails. The terminal tells me that a higher version is available, but it...

24 Feb at 22:30

Best way to convert string to bytes in Python 3?

Best way to convert string to bytes in Python 3? [TypeError: 'str' does not support the buffer interface](https://stackoverflow.com/questions/5471158/typeerror-str-does-not-support-the-buffer-interfac...

What is the difference between range and xrange functions in Python 2.X?

What is the difference between range and xrange functions in Python 2.X? Apparently xrange is faster but I have no idea why it's faster (and no proof besides the anecdotal so far that it is faster) or...

26 Nov at 09:17

ImportError: No module named PIL

ImportError: No module named PIL I use this command in the shell to install PIL: then I run `python` and type this: `import PIL`. But I get this error: I've never had such problem, what do you think?

How can I Install a Python module within code?

How can I Install a Python module within code? I need to install a package from [PyPI](https://en.wikipedia.org/wiki/Python_Package_Index) straight within my script. Is there maybe some module or `dis...

23 Feb at 05:30