Questions tagged [python-3.x]

33864 questions
0

votes
0

answer
3

Views

Bulk exporting google docs as .zipped html files

I'm basically wanting the same output as I would get for exporting a single file as html, zipped; but for a folder full of files. Ideally there's some built-in function I don't know about. I looked through the gdocs python api, but I didn't see anything that really looked like a solution to what I'...
Toph
1

votes
1

answer
3.1k

Views

Beautifulsoup and Soupstrainer for getting links dont work with hasattr, returning always true

i am using Beautifulsoup4 and Soupstrainer with Python 3.3 for getting all links from a webpage. The following is the important code-snippet: r = requests.get(adress, headers=headers) for link in BeautifulSoup(r.text, parse_only=SoupStrainer('a')): if hasattr(link, 'href'): I tested some webpages an...
zwieback86
1

votes
1

answer
640

Views

SublimeText3 plugin on_modified api implementation

I'm trying to develop some plugin for SublimeText3. The plugin is supposed to behave on every modification of the text, so looking at the api http://www.sublimetext.com/docs/3/api_reference.html on_modified_async(view) is the one to use I guessed. so the code goes like this: #!/usr/bin/env python im...
Ken OKABE
1

votes
2

answer
907

Views

Changing color of text in a tkinter window by using colorchooser in python 3 and tkinter

Try to choose the color of the then print it, the printing bit works just need to get the color part working. If you need to see more of the code just ask. def mColour(): color = colorchooser.askcolor() color_name = color[1] mlabel2 = Label(mGui,text=color).pack() messagebox.showinfo(title = "Colour...
Minigeek22
0

votes
0

answer
26

Views

Can I define and setup a context manager before using with

I am using requests to create a requests.Session and set it up inside a function: def create_web_session(cookie=None): s = requests.Session() if cookie is not None: s.cookies.set("my_cookie_name", cookie) return s Sessions can be used as context managers. Can I use the function that returns the sess...
pkiller162
3

votes
0

answer
25

Views

Gather subtensor of padded tensor of variable-sized data in Tensorflow

I have some variable-length sequencial data of fixed tensor dimension. Consider a list of tensors s_1, ..., s_b of a list of some fixed dimensional matrices [l_1,m,n], ..., [l_b,m,n]. For example s_1 = [ [[1,2],[3,4]], [[5,6],[7,8]] ] s_2 = [ [[9,10],[11,12]], [[13,14],[15,16]], [[17,18],[19,20]] ]...
user447457
1

votes
2

answer
3k

Views

Pause execution until button press

I have a QStackedWidget. In the logic (not the UI) I am trying to change pages and wait there until a button on that page is pressed (basically an OK/Cancel). I pass the UI to the function in the class. Something like this: def func1(self, window): window.stackedWidget.setCurrentIndex(4) while True...
Faller
1

votes
2

answer
881

Views

Pythonic way of using Python3's functools.singledispatch in a class?

I'm making the transition over to Python3 and have been exploring some of the functionality of the stdlib. functools.singledispatch caught my eye and I've been playing around with it a little bit. However, at the point where I tried using it in a class I ran into some problems. It doesn't appear to...
synthesizerpatel
1

votes
2

answer
243

Views

Is compiled multi-threaded Python affected by the GIL

As the GIL is a lock that surrounds the interpreter does it affect compiled Python? I'm wondering whether it is possible to get past the inherent multi-threading limitations of cpython by simply compiling my python before executing it. Hopefully that makes sense and I'm not missing something obvious...
mattdavis90
2

votes
1

answer
16

Views

Python - local variable keeps content repeatedly called function

I have the following example: def some_function(input1, some_list=[]): if some_list==[]: some_list.append(input1) if input1 % 3 != 0: some_list.append('last_one') else: some_list.append(input1/3) some_list = some_function(input1/3, some_list) return some_list def main(): #first call print(some_funct...
Egirus Ornila
-3

votes
0

answer
22

Views

I am not able to understand purpose of counting backslashes in below code

From this site, I found below code. Here is the Gist of code import re def test_patterns(text, patterns): # Look for each pattern in the text and print the results for pattern, desc in patterns: print("'{}' ({})\n".format(pattern, desc)) print(" '{}'".format(text)) for match in re.finditer(pattern,...
TapanHP
0

votes
1

answer
18

Views

How to format the irregular datetime strings

I am getting a datetime format like '2019-12-02 12:400:00", "2019-12-02 120:4p:00" from a api call. How to format it to make it proper date time format.
Balasubramanian Raju
0

votes
0

answer
3

Views

Hide legend from seaborn pairplot

I would like to hide the Seaborn pairplot legend. The official docs don't mention a keyword legend. Everything I tried using plt.legend didn't work. Please suggest the best way forward. Thanks! import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline test = pd.DataFrame({ 'id': ['1',...
aviss
1

votes
0

answer
14

Views

Manipulate stack trace of exception before throwing (Python)

I am working on a lazy evaluation library in Python which allows the user to write normal code, while it is evaluated at a later point in time. A problem is that the exceptions are quite confusing. This is why I would like to throw the exception with a modified stack trace. It should look as if the...
Joel Richard
1

votes
1

answer
3.2k

Views

Python subprocess command to run silent, prevent cmd from appearing [duplicate]

This question already has an answer here: How do I hide the console when I use os.system() or subprocess.call()? 4 answers I have some complicated Python3 GUI code with tinker, and compiled with cx_Freeze. The issue only occurs when run on Windows. subprocess check_ouptut (or Popen) runs a similar...
Sazzy
1

votes
4

answer
5.9k

Views

Find maximum and minimum value of a matrix

I have this code wrote in python 3: matrix = [] loop = True while loop: line = input() if not line: loop = False values = line.split() row = [int(value) for value in values] matrix.append(row) print('\n'.join([' '.join(map(str, row)) for row in matrix])) print('matrix saved') an example of returned...
Jon_Computer
1

votes
3

answer
60

Views

String Manipulation with Regular Expression specifically or statements

I am trying to parse out certain strings from a phrase. This is the phrase: '1st Floor 2nd Floor 3rd Floor 4th Floor' The end phrase should be: '1st Floor','2nd Floor','3rd Floor','4th Floor' I am having trouble getting the '1st','2nd','3rd','4th' parts of the regex. I know I can do a less-intuitive...
user3683871
1

votes
0

answer
15

Views

How to compare datetime between dataframes in multi logic statements?

I am having issue comparing dates between two dataframes from inside a multi logic statement. df1: email datetimecreated [email protected] 2019-02-12 20:47:00 df2: EmailAddress DateTimeCreated [email protected] 2019-02-07 20:47:00 [email protected] 2018-11-13 20:47:00 [email protected] 2018-11-04 20:47:...
RustyShackleford
1

votes
1

answer
23

Views

How to loop through all variables from a python class object (without converting them to string)?

Lets say I have a class like this: class Colors: RED = '\33[31m' GREEN = '\33[32m' YELLOW = '\33[33m' BLUE = '\33[34m' ... How can I loop through these variables without turning them into strings? eg: for color in Colors: print(color + 'foo') //should print foo in terminal in each color I attempted...
Jane
0

votes
1

answer
50

Views

Send SIGTERM to the running task, dask distributed

When I submit a small Tensorflow training as a single task, it launches additional threads. When I press Ctrl+C and raise KeyboardInterrupt my task is closed but underlying threads are not cleaned up and training continues. Initially, I was thinking that this is a problem of Tensorflow (not cleaning...
0

votes
0

answer
5

Views

Using PIL to show image (png) in terminal

Environment: Python 3.7.2 Mac OS 10.14.3 I am try to find a way to show a image (jpg/png) in the terminal application. And I found a working solution for jpg image here: Display Images in Linux Terminal using Python With the following code: import numpy as np from PIL import Image def get_ansi_color...
supersuraccoon
1

votes
0

answer
8

Views

ValueError: invalid literal for int() with base 10 with odoo

I have a date field in form that allows the users to enter a date which presumably the deadline of a task and I want to have difference between today with deadline and concern of: 1.if the date has passed, then show 'overdue' 2.if not, then show the number of days left the given date and add text th...
user7405045
1

votes
2

answer
1k

Views

How to make sure that random.choice() doesn't pick the same item twice?

I am making a quiz. That means I have to generate random questions for a list, but I need to make sure that questions aren't repeated. I am using Python 3.1.4, but I dont know how to make sure it checks if the string hasn't already been generated. The piece of code that I am using to generate the s...
James
1

votes
1

answer
898

Views

How to document nested classes with Sphinx's autodoc?

Is there any way to document a nested class with Sphinx's autodoc plugin? In: class A: class B: """ class B's documentation. """ # ... I want to use autoclass or something similar in my .rst file to document A.B specifically. I tried: .. currentmodule:: package.module .. autoclass:: A.B and .. autoc...
eepp
1

votes
1

answer
604

Views

Using pyenv to switch between two system versions of Python

Is it possible to have pyenv switch between two system versions of Python? I have recently installed Ubuntu 14.04 on my laptop, and it comes shipped with both python2 (v2.7.6) and python3 (v3.4.0) commands. (And the command python links to python2). After installing pyenv, and typing pyenv versions...
Håkon Hægland
0

votes
0

answer
28

Views

Extracting number from html files

I am new to Python and I am learning how to search for the same piece of data from multiple html files. The files have been downloaded and stored. The code opens the webpage source and the specific number I'm trying to get is difficult since all the html files have different html tags enclosed aroun...
David
0

votes
0

answer
6

Views

How to create a SSIS package to ETL JSON from Python REST API request into MSSQL server?

I am trying to take a Python script I wrote that makes GET requests utilizing a REST API and returns data in the form of JSON and then have that data be inserted into a MSSQL server that I will have to create. This job will need to run each day at least once. I am not familiar with creating tables...
Dylan Janszen
1

votes
1

answer
56

Views

Python Improperly configured URL [closed]

I'm pretty new to python and Django development. I'm using Python 3.4.0 and Django 1.7.3. I am following the django docs tutorials, everything is working fine until part 3 of the tutorial. In part 3, when I make my view I'm getting the error(screenshot attached.) Following is my urls.py of applicati...
htyagi
1

votes
3

answer
3.6k

Views

Generate a random number from an interval in Python

How to generate a random number in the interval [-0.5, 0.5] using Python random() or randrange() functions?
0

votes
5

answer
20

Views

Python partitioning string list by using for loop conditional statement

I'd like to remove all letters after a certain string, for example, removing words after Hello and Hi inside my_list (just like my code below), and return a new cleaned list. I tried to use partition inside for loop conditional statement but it just returned the original list. Is there any way to mo...
Jay
0

votes
1

answer
19

Views

Python Pandas - Replacing relevant texts fails

I am trying to compare two columns - primary column and secondary column. The secondary column might have a(.) or a text like " (On Leave) after the desired string. I learned that to replace ("."), it has to be passed with ("\.") If the secondary column holds a particular value like "NOTAPPLICABLEH...
Sid29
0

votes
0

answer
4

Views

IndexError: image index out of range when using a nested for-loop and using (i,j)

My aim is to search each pixel in the box to see if their rgb is the same as col. While there have been other posts on indexError most were due to the counter going negative or similar but I simply don't see how this could go out of range considering the counters are in terms of the index size (the...
Echo11
1

votes
0

answer
4

Views

pywinauto capture_as_image adds unwanted borders

I am using pywinauto to take a screenshot of a specific window. Here is the code I use to take a capture of notepad ("Bloc-notes" in french) : from pywinauto import Application app = Application().connect(title_re=".*Bloc-notes") hwin = app.top_window() hwin.set_focus() img = hwin.capture_as_image()...
Simpom
0

votes
0

answer
4

Views

Why the time for queries oscilates in a sqlite3 database?

I was testing the difference in time between querying a database, which is stored in an external hard drive, using sqlalchemy and raw SQLite3 in order to see which would give me the best times and found the results to be oscillating in time: The code used for each step is: def time_attack_alchemy():...
Chicrala
1

votes
2

answer
3.2k

Views

'_io.TextIOWrapper' no attribute 'replace'

I'm pretty new to Python. I'm trying to learn how to create modules and import functions, so the reason this is in two files is because I'm fooling around with that. It seems to me that that's not the problem though, but I figured I'd put some backstory in there in case it was relevant. I know my fo...
Chris Gleason
1

votes
2

answer
6.3k

Views

Filtering CSV rows by specific column data

I'd like to filter a CSV file (without headers) containing hundreds of rows based on the value in column 12. Values that filter these rows contain data like "00GG", "05FT", "66DM" and 10 more. With the code below I'm able to print rows based on one criteria: def load_source(filename): with open(file...
strongbad
1

votes
3

answer
3.5k

Views

Deploy a python3.4-based Django project on Centos 6.5 with mod_wsgi: doable?

I have a project that works very nicely using the dev web server but I'm running into tons of problems getting it to play nice on an old-ish centos box with the system apache (ie installed via yum.) I uninstalled the yum-based wsgi (because it was assuredly compiled against the system python 2.x) a...
Owen
1

votes
3

answer
17

Views

Custom validation is not working inside forms.py

I want to validate my email field like: if email contains [gmail.com,outlook.com,yahoo.com] then raise validation Error.But it's not working,don't know where i am doing wrong. plz help me views.py from django.shortcuts import render from django.views.generic import View from access.utils import is...
lpd
-1

votes
0

answer
28

Views

Python: Function returns None instead of given value

I'm having a weird issue with returning functions. I'm trying to assign the return value of a function to a veriable, but it's always returning None, even though the variable is correctly being used in the function itself. The function jumps around different parts of a package, so here's the relevan...
polarisfox64
-2

votes
1

answer
32

Views

Replace all newline characters using python

I am trying to read a pdf using python and the content has many newline (crlf) characters. I tried removing them using below code: from tika import parser filename = 'myfile.pdf' raw = parser.from_file(filename) content = raw['content'] content = content.replace("\r\n", "") print(content) But the ou...
Leni

View additional questions