python-3.x

django2: How to use different templates?

点点圈 提交于 2021-02-10 18:26:11
问题 Say I created a django project called django_site . I created two sub-projects: site1 and polls . You see that I have two index.html in two sub-projects directories. However, now, if I open on web browser localhost:8000/site1 or localhost:8000/polls , they all point to the index.html of polls . How can I configure so when I open localhost:8000/site1 it will use the index.html of site1 ? My settings.py in django_site directory: .. TEMPLATES = [ { 'BACKEND': 'django.template.backends.django

Selenium printing same information repeatedly

我的未来我决定 提交于 2021-02-10 18:25:03
问题 Hello I am trying to scrape some data from a website that has data in its 'dl' tag here is how the website structure looks <div class="ecord-overview col-md-5"> <h2><span itemprop="name">Donald Duck</span></h2> dl class="row"> </dd> <dt class="col-md-4">Email</dt> <dd class="col-md-8">myemail.com</dd> </dl> <div class="ecord-overview col-md-5"> <h2><span itemprop="name">Mickey mouse</span></h2> dl class="row"> </dd> <dt class="col-md-4">Email</dt> <dd class="col-md-8">youremail.com</dd> </dl>

Dash download in-memory generated file on button click: How to give filename?

回眸只為那壹抹淺笑 提交于 2021-02-10 18:21:46
问题 I generate an in-memory Excel file via pd.ExcelWriter and BytesIO for a click event in my Python3.8 dash app. Everything works as it should be. When I download my file I get this popup message asking me if I would like to continue to download/open the generated file. However, the popup message shows this (I guess base64 encoded) string (or path?), e.g. ...ydaHdjhgk328AAAAnxsAA== and after downloading the download gets a (randomly assigned?) set of characters as the filename (e.g. ZySzsdn1

Sorting rows in python pandas

房东的猫 提交于 2021-02-10 18:17:30
问题 I have a dataframe (the sample looks like this) Type SKU Description FullDescription Size Price Variable 2 Boots Shoes on sale XL,S,M Variation 2.5 Boots XL XL 330 Variation 2.6 Boots S S 330 Variation 2.7 Boots M M 330 Variable 3 Helmet Helmet Sizes E42,E41 Variation 3.8 Helmet E42 E42 89 Variation 3.2 Helmet E41 E41 89 What I want to do is sort the values based on Size so the final data frame should look like this: Type SKU Description FullDescription Size Price Variable 2 Boots Shoes on

Error opening Excel (XLSX) files from pandas xlsxwriter

六眼飞鱼酱① 提交于 2021-02-10 18:12:00
问题 Upon opening an XLSX file in MS Excel, an error dialog is presented: "We found a problem with some content in filename.xlsx ..." Clicking "Yes" to attempt recovery yields the following XML error message: <?xml version="1.0" encoding="UTF-8" standalone="true"?> -<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <logFileName>error359720_09.xml</logFileName> <summary>Errors were detected in file 'C:\Users\username\Github\Project\Data\20200420b.xlsx'</summary> -

RuntimeError: File descriptor 8 is used by transport

ⅰ亾dé卋堺 提交于 2021-02-10 17:52:27
问题 Minimal demonstration example: import asyncio async def main(): c1_reader, c1_writer = await asyncio.open_connection(host='google.com', port=80) c1_socket = c1_writer.get_extra_info('socket') c1_socket.close() c2_reader, c2_writer = await asyncio.open_connection(host='google.com', port=80) asyncio.run(main()) Running this program gives this error: $ python3 asyncio_fd_used.py Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7

Error opening Excel (XLSX) files from pandas xlsxwriter

穿精又带淫゛_ 提交于 2021-02-10 17:50:33
问题 Upon opening an XLSX file in MS Excel, an error dialog is presented: "We found a problem with some content in filename.xlsx ..." Clicking "Yes" to attempt recovery yields the following XML error message: <?xml version="1.0" encoding="UTF-8" standalone="true"?> -<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <logFileName>error359720_09.xml</logFileName> <summary>Errors were detected in file 'C:\Users\username\Github\Project\Data\20200420b.xlsx'</summary> -

Find the most common element in list of lists

一曲冷凌霜 提交于 2021-02-10 17:44:09
问题 This is my list a=[ ['a','b','a','a'], ['c','c','c','d','d','d']] I wanna find most common elemments. I have tried this from collections import Counter words = ['hello', 'hell', 'owl', 'hello', 'world', 'war', 'hello', 'war','aa','aa','aa','aa'] counter_obj = Counter(words) counter_obj.most_common() but it works just for simple list. my output should be like this [('a', 3), ('c', 3), ('d', 3), ('b', 1)] 回答1: Apply Counter().update() option on the elements of your list, Based on suggestion

python input() takes old stdin before input() is called

夙愿已清 提交于 2021-02-10 17:35:42
问题 Python3's input() seems to take old std input between two calls to input() . Is there a way to ignore the old input, and take new input only (after input() gets called)? import time a = input('type something') # type "1" print('\ngot: %s' % a) time.sleep(5) # type "2" before timer expires b = input('type something more') print('\ngot: %s' % b) output: $ python3 input_test.py type something got: 1 type something more got: 2 回答1: You can flush the input buffer prior to the second input() , like

requests library: Failed to establish a new connection: [Errno 13] Permission denied

不羁的心 提交于 2021-02-10 17:28:13
问题 I have a python script which uses requests library to connect to a device with its web-interface. It uses a url with https connection. sess = requests.Session() try: resp = sess.post('https://' + device + '/url_admin/login.cgi', data=login_data, verify=False) except Exception as e: template = "Exception: {0}\nArguments: {1!r}" print(template.format(type(e).__name__, e.args)) When I try to execute it from command line it works perfectly (even with apache user). However, when it is triggered