qid int64 46k 74.7M | question stringlengths 54 37.8k | date stringlengths 10 10 | metadata listlengths 3 3 | response_j stringlengths 17 26k | response_k stringlengths 26 26k |
|---|---|---|---|---|---|
4,837,218 | Last night I came across the term called Jython which was kind of new to me so I started reading about it only to add more to my confusion about Python in general. I have never really used Python either. So here is what I am confused about.
1. `Python is implemented in C` - Does that mean that the interpreter was writ... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4837218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/568638/"
] | a) Python is a programming language. Interpreters of Python code are implemented using other programming languages like C (PyPy even using Python itself to implement one, I believe).
b) CPython, aka Classic Python, is the reference implementation and is written in C. Jython is a Python interpreter written in Java.
c)... | a) Default and most widely used language implementation is written in c also caled CPython. There is also for instance Python implemented in Python - <http://codespeak.net/pypy/dist/pypy/doc/>
b) CPython is default python implemetation in C. Jython is implemetation in Java.
c) Yes.
d) Jython is implementation of Pyt... |
4,837,218 | Last night I came across the term called Jython which was kind of new to me so I started reading about it only to add more to my confusion about Python in general. I have never really used Python either. So here is what I am confused about.
1. `Python is implemented in C` - Does that mean that the interpreter was writ... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4837218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/568638/"
] | 1. The former.
2. I suppose yes. Strictly speaking, "Python" refers only to the language (regardless of the implementation) - but unless the distinction important (e.g. when discussing implementations details), it can also refer to implementations. "CPython" is an unambiguous name for the oldest, most widely-used imple... | a) Python is a programming language. Interpreters of Python code are implemented using other programming languages like C (PyPy even using Python itself to implement one, I believe).
b) CPython, aka Classic Python, is the reference implementation and is written in C. Jython is a Python interpreter written in Java.
c)... |
4,837,218 | Last night I came across the term called Jython which was kind of new to me so I started reading about it only to add more to my confusion about Python in general. I have never really used Python either. So here is what I am confused about.
1. `Python is implemented in C` - Does that mean that the interpreter was writ... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4837218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/568638/"
] | 1. The former.
2. I suppose yes. Strictly speaking, "Python" refers only to the language (regardless of the implementation) - but unless the distinction important (e.g. when discussing implementations details), it can also refer to implementations. "CPython" is an unambiguous name for the oldest, most widely-used imple... | a) Default and most widely used language implementation is written in c also caled CPython. There is also for instance Python implemented in Python - <http://codespeak.net/pypy/dist/pypy/doc/>
b) CPython is default python implemetation in C. Jython is implemetation in Java.
c) Yes.
d) Jython is implementation of Pyt... |
46,431,145 | so im a python beginner and i cant find a way to put a input varible in a random like so,
```html
import time
import random
choice = input('easy (max of 100 number), medium(max of 1000) or hard (max of 5000)? Or custom)')
time.sleep(2)
if choice == 'custom':
cus = input(' max number?')
print ('okey dokey!')... | 2017/09/26 | [
"https://Stackoverflow.com/questions/46431145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8677673/"
] | There are multiple things wrong with your code. You're using ('s with print, which suggests you're using python3. This means that when you do `cus = input()`, cus is now a string. You probably want to do `cus = int(input())`
Doing `choice == 'easy' or 'medium' or 'hard' or cus` will always be True; I have no idea why ... | Convert your variable `cus` to an int and pass it as you normally would
```
cuss = random.randrange(0, int(cus))
``` |
7,817,926 | I'm trying to use scapy on win32 python2.7
I've manage to compile all the other dependencies expect this one
can some help in the goal of reaching this executable ?
"dnet-1.12.win32-py2.7.exe"
(I promise to update the this question too and the scapy manual,
[Running Scapy on Windows with Python 2.7](https://stackov... | 2011/10/19 | [
"https://Stackoverflow.com/questions/7817926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/459189/"
] | I just called super on the following overridden method of the BaseExpandableListAdapter and since then the notifyDataSetChanged() works.
```
@Override
public void registerDataSetObserver(DataSetObserver observer) {
super.registerDataSetObserver(observer);
}
``` | you can try to additionally call invalidateViews() on your ExpandableListView when refreshing. |
7,817,926 | I'm trying to use scapy on win32 python2.7
I've manage to compile all the other dependencies expect this one
can some help in the goal of reaching this executable ?
"dnet-1.12.win32-py2.7.exe"
(I promise to update the this question too and the scapy manual,
[Running Scapy on Windows with Python 2.7](https://stackov... | 2011/10/19 | [
"https://Stackoverflow.com/questions/7817926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/459189/"
] | you can try to additionally call invalidateViews() on your ExpandableListView when refreshing. | You have to wait until the whole viewtree has been drawn and then you can call notifyDataSetChanged()
*"A view tree observer is used to register listeners that can be notified of global changes in the view tree. Such global events include, but are not limited to, layout of the whole tree, beginning of the drawing pass... |
7,817,926 | I'm trying to use scapy on win32 python2.7
I've manage to compile all the other dependencies expect this one
can some help in the goal of reaching this executable ?
"dnet-1.12.win32-py2.7.exe"
(I promise to update the this question too and the scapy manual,
[Running Scapy on Windows with Python 2.7](https://stackov... | 2011/10/19 | [
"https://Stackoverflow.com/questions/7817926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/459189/"
] | you can try to additionally call invalidateViews() on your ExpandableListView when refreshing. | If you are using Expandable lists of Big Nerd Ranch, please note that traditional `notifyDataSetChanged()` of `RecyclerView.adapter` is not working.
Instead Expandable RecyclerView provides a set of notify methods with the ability to inform the adapter of changes to the list of ParentListItems.
```
// Parent Changes... |
7,817,926 | I'm trying to use scapy on win32 python2.7
I've manage to compile all the other dependencies expect this one
can some help in the goal of reaching this executable ?
"dnet-1.12.win32-py2.7.exe"
(I promise to update the this question too and the scapy manual,
[Running Scapy on Windows with Python 2.7](https://stackov... | 2011/10/19 | [
"https://Stackoverflow.com/questions/7817926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/459189/"
] | I just called super on the following overridden method of the BaseExpandableListAdapter and since then the notifyDataSetChanged() works.
```
@Override
public void registerDataSetObserver(DataSetObserver observer) {
super.registerDataSetObserver(observer);
}
``` | You have to wait until the whole viewtree has been drawn and then you can call notifyDataSetChanged()
*"A view tree observer is used to register listeners that can be notified of global changes in the view tree. Such global events include, but are not limited to, layout of the whole tree, beginning of the drawing pass... |
7,817,926 | I'm trying to use scapy on win32 python2.7
I've manage to compile all the other dependencies expect this one
can some help in the goal of reaching this executable ?
"dnet-1.12.win32-py2.7.exe"
(I promise to update the this question too and the scapy manual,
[Running Scapy on Windows with Python 2.7](https://stackov... | 2011/10/19 | [
"https://Stackoverflow.com/questions/7817926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/459189/"
] | I just called super on the following overridden method of the BaseExpandableListAdapter and since then the notifyDataSetChanged() works.
```
@Override
public void registerDataSetObserver(DataSetObserver observer) {
super.registerDataSetObserver(observer);
}
``` | If you are using Expandable lists of Big Nerd Ranch, please note that traditional `notifyDataSetChanged()` of `RecyclerView.adapter` is not working.
Instead Expandable RecyclerView provides a set of notify methods with the ability to inform the adapter of changes to the list of ParentListItems.
```
// Parent Changes... |
61,038,562 | I'm writing a program where I'm converting a function to prefix and calculate.
```
from pythonds.basic import Stack
def doMath(op, op1, op2):
if op == "*":
return int(op1) * int(op2)
elif op == "/":
return int(op1) / int(op2)
elif op == "+":
return int(op1) + int(op2)
elif ... | 2020/04/05 | [
"https://Stackoverflow.com/questions/61038562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7737188/"
] | When you try:
```
if token in "0123456789":
operandStack.push(token)
```
for `token = 17`, this shall fail since `17` is not in `0123456789`.
So change it to this:
```
try:
if float(token):
operandStack.push(token)
except:
#your code here
```
---
**HOW THIS WORKS:**
When a type of `str`... | Replace `if token in "0123456789"` (checks if `token` is a substring of `"0123456789"`) with `if token.isdigit()` (checks if `token` consists of decimal digits). |
9,816,139 | I've got an old RRD file that was only set up to track 1 year of history. I decided more history would be nice. I did rrdtool resize, and the RRD is now bigger. I've got old backups of this RRD file and I'd like to merge the old data in so that the up-to-date RRD also has the historical data.
I've tried the rrd contri... | 2012/03/22 | [
"https://Stackoverflow.com/questions/9816139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91238/"
] | I ended up putting together a really simple script that works well enough for my case, by examining the existing python script.
<http://gist.github.com/2166343> | Looking at the XML file generated by rrdtool, there is a simple logic error in the Perl script. The elements AVERAGE and are simple enough but the tag is contained within tag with the text inside.
```
<cf> AVERAGE </cf>
<pdp_per_row> 1 </pdp_per_row> <!-- 300 seconds -->
<params>
... |
9,816,139 | I've got an old RRD file that was only set up to track 1 year of history. I decided more history would be nice. I did rrdtool resize, and the RRD is now bigger. I've got old backups of this RRD file and I'd like to merge the old data in so that the up-to-date RRD also has the historical data.
I've tried the rrd contri... | 2012/03/22 | [
"https://Stackoverflow.com/questions/9816139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91238/"
] | I ended up putting together a really simple script that works well enough for my case, by examining the existing python script.
<http://gist.github.com/2166343> | That fixed rrdtool-merge.pl for me:
```
< my $xff = $new_rra->first_child( 'xff' )->text;
---
> my $xff = $new_rra->first_child_text( 'xff' );
```
From XML::Twig documentation:
```
first_child_text ($optional_condition)
Return the text of the first child of the element, or the first ... |
9,816,139 | I've got an old RRD file that was only set up to track 1 year of history. I decided more history would be nice. I did rrdtool resize, and the RRD is now bigger. I've got old backups of this RRD file and I'd like to merge the old data in so that the up-to-date RRD also has the historical data.
I've tried the rrd contri... | 2012/03/22 | [
"https://Stackoverflow.com/questions/9816139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91238/"
] | I ended up putting together a really simple script that works well enough for my case, by examining the existing python script.
<http://gist.github.com/2166343> | The rrdmerge.pl utility, included with Routers2 in the /extras directory, can do this. Collect the latest version of Routers2 from <http://www.steveshipway.org/software/rrd/>
This is a utility I wrote for the purpose of merging multiple archived MRTG RRD files which sounds exactly like the situation you are mentioning... |
9,816,139 | I've got an old RRD file that was only set up to track 1 year of history. I decided more history would be nice. I did rrdtool resize, and the RRD is now bigger. I've got old backups of this RRD file and I'd like to merge the old data in so that the up-to-date RRD also has the historical data.
I've tried the rrd contri... | 2012/03/22 | [
"https://Stackoverflow.com/questions/9816139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91238/"
] | That fixed rrdtool-merge.pl for me:
```
< my $xff = $new_rra->first_child( 'xff' )->text;
---
> my $xff = $new_rra->first_child_text( 'xff' );
```
From XML::Twig documentation:
```
first_child_text ($optional_condition)
Return the text of the first child of the element, or the first ... | Looking at the XML file generated by rrdtool, there is a simple logic error in the Perl script. The elements AVERAGE and are simple enough but the tag is contained within tag with the text inside.
```
<cf> AVERAGE </cf>
<pdp_per_row> 1 </pdp_per_row> <!-- 300 seconds -->
<params>
... |
9,816,139 | I've got an old RRD file that was only set up to track 1 year of history. I decided more history would be nice. I did rrdtool resize, and the RRD is now bigger. I've got old backups of this RRD file and I'd like to merge the old data in so that the up-to-date RRD also has the historical data.
I've tried the rrd contri... | 2012/03/22 | [
"https://Stackoverflow.com/questions/9816139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91238/"
] | The rrdmerge.pl utility, included with Routers2 in the /extras directory, can do this. Collect the latest version of Routers2 from <http://www.steveshipway.org/software/rrd/>
This is a utility I wrote for the purpose of merging multiple archived MRTG RRD files which sounds exactly like the situation you are mentioning... | Looking at the XML file generated by rrdtool, there is a simple logic error in the Perl script. The elements AVERAGE and are simple enough but the tag is contained within tag with the text inside.
```
<cf> AVERAGE </cf>
<pdp_per_row> 1 </pdp_per_row> <!-- 300 seconds -->
<params>
... |
65,131,966 | Say I have a collection of scripts organized for convenience in a directory structure like so:
```
root
│ helpers.py
│
├───dir_a
│ data.txt
│ foo.py
│
└───dir_b
data.txt
bar.py
```
`foo.py` and `bar.py` are scripts doing different things, but they both load their distinct `data.txt` the... | 2020/12/03 | [
"https://Stackoverflow.com/questions/65131966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7227829/"
] | I don't think there is a way to have node do what you want. I had a similar where the main project was commonjs but one of the libraries was esm or a library it was using was esm. I don't remember the specific details but it was a royal pain.
The basic work around is to use `esm` to `import` the library giving you iss... | I had the same issue and I used single quotation for multi-value args like `--exec' to solve it.
```
nodemon --watch 'src/**/*' -e ts,tsx --exec 'ts-node ./src/index.ts'
``` |
8,587,633 | I'm trying to write a python script for BusyBox on ESXi with mail functionality. It runs Python 2.5 with some libraries missing (i.e. the smtplib). I downloaded Python2.5 sources and copied the lib-folder to ESXi. Now I am trying to import the smtplib via "import lib.smtplib" but Python says:
```
Traceback (most recen... | 2011/12/21 | [
"https://Stackoverflow.com/questions/8587633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921051/"
] | Trying to install generic applications on an appliance or custom OS is always fun.
Just a guess, but it may be that the email lib is a compiled C module - i.e. not pure python.
I would try use libraries that are as completely python with no compiled code - I don't know if there are pure python versions of the librari... | I don't know anything about BusyBox or ESXi - therefore this may be more of a suggestion than an answer, but you might consider using a email service that supports an HTTP or RESTful API - such as [MailGun](http://documentation.mailgun.net/wrappers.html#python). They have a free plan for up to 200 emails a day, so it m... |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | Use the IDLE extension called IDLE2HTML.py (search for this).
This lets IDLE print to an HTML file that has color in its style sheet.
Then save the HTML file to a PDF (the color will still be there). | I had the same problem and opened the py file into Visual Studio Code, then simply copied (Ctrl A / Ctrl C) and pasted the text (Ctrl V) into a Microsoft editor such as Word or RTF, or even outlook. The colors stay, including when printing.
Note that in order to avoid the night mode set as a default in VS Code, go to ... |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | IDLE can't do it, but you can do it in an indirect way: Use LaTeX to format your script with the IDLE colors.
The [`listings`](http://www.ctan.org/tex-archive/macros/latex/contrib/listings/) package supports IDLE-like colorizing for python, but it's pretty well hidden: You must know to include a "preference file" that... | I do this all the time with large amounts of code.
Just install SciTE "https://www.scintilla.org/SciTEDownload.html"
Copy and paste your code and print.
I like to grab some tape and markers stick all the sheets on a wall and put some music on.
Happy coding! |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | The easiest way is to open the '.py' file with [Notepad++](https://notepad-plus-plus.org/) and there you can select and modify your settings and preferences (any theme you want for your python codes) to export the python file to a colorful PDF file (using PDF Virtual Printer) or directly print it :-) .
OR
If you are ... | I do this all the time with large amounts of code.
Just install SciTE "https://www.scintilla.org/SciTEDownload.html"
Copy and paste your code and print.
I like to grab some tape and markers stick all the sheets on a wall and put some music on.
Happy coding! |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | A good and simple solution is to use ***IDLE2HTML***, an extension for IDLE.
The tool allows IDLE to save code from the editor window (or interactive shell) to a HTML file,
with colour included in the CSS format. After this, the file can be printed (as asked for) or its formatted code used with other programs suc... | I do this all the time with large amounts of code.
Just install SciTE "https://www.scintilla.org/SciTEDownload.html"
Copy and paste your code and print.
I like to grab some tape and markers stick all the sheets on a wall and put some music on.
Happy coding! |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | A good and simple solution is to use ***IDLE2HTML***, an extension for IDLE.
The tool allows IDLE to save code from the editor window (or interactive shell) to a HTML file,
with colour included in the CSS format. After this, the file can be printed (as asked for) or its formatted code used with other programs suc... | I had the same problem and opened the py file into Visual Studio Code, then simply copied (Ctrl A / Ctrl C) and pasted the text (Ctrl V) into a Microsoft editor such as Word or RTF, or even outlook. The colors stay, including when printing.
Note that in order to avoid the night mode set as a default in VS Code, go to ... |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | The easiest way is to open the '.py' file with [Notepad++](https://notepad-plus-plus.org/) and there you can select and modify your settings and preferences (any theme you want for your python codes) to export the python file to a colorful PDF file (using PDF Virtual Printer) or directly print it :-) .
OR
If you are ... | I had the same problem and opened the py file into Visual Studio Code, then simply copied (Ctrl A / Ctrl C) and pasted the text (Ctrl V) into a Microsoft editor such as Word or RTF, or even outlook. The colors stay, including when printing.
Note that in order to avoid the night mode set as a default in VS Code, go to ... |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | IDLE can't do it, but you can do it in an indirect way: Use LaTeX to format your script with the IDLE colors.
The [`listings`](http://www.ctan.org/tex-archive/macros/latex/contrib/listings/) package supports IDLE-like colorizing for python, but it's pretty well hidden: You must know to include a "preference file" that... | A good and simple solution is to use ***IDLE2HTML***, an extension for IDLE.
The tool allows IDLE to save code from the editor window (or interactive shell) to a HTML file,
with colour included in the CSS format. After this, the file can be printed (as asked for) or its formatted code used with other programs suc... |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | IDLE can't do it, but you can do it in an indirect way: Use LaTeX to format your script with the IDLE colors.
The [`listings`](http://www.ctan.org/tex-archive/macros/latex/contrib/listings/) package supports IDLE-like colorizing for python, but it's pretty well hidden: You must know to include a "preference file" that... | Use the IDLE extension called IDLE2HTML.py (search for this).
This lets IDLE print to an HTML file that has color in its style sheet.
Then save the HTML file to a PDF (the color will still be there). |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | IDLE can't do it, but you can do it in an indirect way: Use LaTeX to format your script with the IDLE colors.
The [`listings`](http://www.ctan.org/tex-archive/macros/latex/contrib/listings/) package supports IDLE-like colorizing for python, but it's pretty well hidden: You must know to include a "preference file" that... | The easiest way is to open the '.py' file with [Notepad++](https://notepad-plus-plus.org/) and there you can select and modify your settings and preferences (any theme you want for your python codes) to export the python file to a colorful PDF file (using PDF Virtual Printer) or directly print it :-) .
OR
If you are ... |
16,833,285 | I have searched for an answer to this but the related solutions seem to concern `'print'`ing in the interpreter.
I am wondering if it is possible to print (physically on paper) python code in color from IDLE?
I have gone to: `File > Print Window` in IDLE and it seems to just print out a black and white version withou... | 2013/05/30 | [
"https://Stackoverflow.com/questions/16833285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063287/"
] | Use the IDLE extension called IDLE2HTML.py (search for this).
This lets IDLE print to an HTML file that has color in its style sheet.
Then save the HTML file to a PDF (the color will still be there). | I do this all the time with large amounts of code.
Just install SciTE "https://www.scintilla.org/SciTEDownload.html"
Copy and paste your code and print.
I like to grab some tape and markers stick all the sheets on a wall and put some music on.
Happy coding! |
24,520,133 | I'd like to download a series of pdf files from my intranet. I'm able to see the files in my web browser without issue, but when trying to automate the pulling of the file via python, I run into problems. After talking through the proxy set up at my office, I can download files from the internet quite easily with this ... | 2014/07/01 | [
"https://Stackoverflow.com/questions/24520133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3746982/"
] | Installing openers into urllib2 doesn't affect requests. You need to use requests' own support for proxies. It should be enough to pass them in the `proxies` argument to `get`, or you can set the `HTTP_PROXY` and `HTTPS_PROXY` environment variables. See <http://docs.python-requests.org/en/latest/user/advanced/#proxies>... | Have you tried not using the proxy to download your files when it's on the intranet?
You could try something like this in python2
```
from urllib2 import urlopen
url = 'http://intranet/myfile.pdf'
with open(local_filename, 'wb') as f:
f.write(urlopen(url).read())
``` |
25,643,943 | I am trying to write a python program in which the user inputs the polynomial and it calculates the derivative. My current code is:
```
print ("Derviatives: ")
k5 = raw.input("Enter 5th degree + coefficent: ")
k4 = raw.input("Enter 4th degree + coefficent: ")
k3 = raw.input("Enter 3rd degree + coefficent: ... | 2014/09/03 | [
"https://Stackoverflow.com/questions/25643943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3953943/"
] | OK, use `raw_input` instead of `raw.input`. It is builtin, as is `int`, so nothing needs importing. When converting to a integer (`int`), you need to assign the result, or nothing will change. You can chain the functions, and use `k5 = int(raw_input("prompt.. "))`. Also, as pointed out by Evert, variable names cannot b... | I see the following issues with your code:
1. Variable names can't start with a digit: `1in`
2. You have undefined variable `Y`. I suppose you want to compare with a string literal, so write `"Y"` instead.
3. Parentheses aren't needed in python's `if` operators, but a trailing colon is necessary. Same goes for `else`.... |
25,643,943 | I am trying to write a python program in which the user inputs the polynomial and it calculates the derivative. My current code is:
```
print ("Derviatives: ")
k5 = raw.input("Enter 5th degree + coefficent: ")
k4 = raw.input("Enter 4th degree + coefficent: ")
k3 = raw.input("Enter 3rd degree + coefficent: ... | 2014/09/03 | [
"https://Stackoverflow.com/questions/25643943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3953943/"
] | Use Sympy:
Put these two lines at the top:
```
from sympy import *
import numpy as np
```
And these at the part """CODE GOES HERE"""
```
x = Symbol('x')
y = k5*x**5 + k4*x**4 + k3*x**3 + k2*x**2 + k1*x +constant
yprime = y.diff(x)
yprime
``` | I see the following issues with your code:
1. Variable names can't start with a digit: `1in`
2. You have undefined variable `Y`. I suppose you want to compare with a string literal, so write `"Y"` instead.
3. Parentheses aren't needed in python's `if` operators, but a trailing colon is necessary. Same goes for `else`.... |
52,651,733 | I try to find refresing elements (time minute) on the webpage. My code worked only for simple text earlier. Now I use *Ctrl+Shift+I* and point out my element and *"Copy Xpath"*.
Also, I have Chrome extension *"XPath helper"* and tried to do that with it one. There is more longer XPath, than in my code below. And it d... | 2018/10/04 | [
"https://Stackoverflow.com/questions/52651733",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10290047/"
] | You should set `Tag` instead of assigning an id to the dynamic created view.
```
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflator=LayoutInflater.from(this.mContext);
View layout=inflator.inflate(R.layout.activity_main, parent, false);
ImageView imageView;
... | The position effectively acts as an id. Or I have missed the point? |
43,207,159 | first of all, i´m pretty new to Python. I also searched for a solution, but i guess the usual approach (subprocess.popen) won´t work in my case.
I have to pass arguments to a listener in an already running python script without starting the script over and over again. There is an example how to pass a message to a lcd... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43207159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5607983/"
] | Once a process is running it won't re-evaluate its command line arguments. You need other ways to communicate with it. This is colloquially called *inter-process communication* (IPC), and there are several ways to achieve it. Here are a few:
* Files
* Pipes (on platforms that support them)
* Shared memory
* Socket com... | You can use some sort of messaging library that will allow you to communicate between processes. [ZeroMQ](http://www.zeromq.org/bindings:python) is a good option, and has python bindings. |
69,259,654 | When I debug, I often find it useful to print a variable's name and contents.
```python
a = 5
b = 7
print("a: "+str(a)+"\n b: "+str(b))
```
I want to write a function that achieves this. So far, I have the following function:
```python
def dprint(varslist, *varnames):
string = [var+": "+str(varslist[var]) for v... | 2021/09/20 | [
"https://Stackoverflow.com/questions/69259654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16337951/"
] | Use [`sys._getframe`](https://docs.python.org/3/library/sys.html#sys._getframe):
>
> Return a frame object from the call stack. If optional integer depth is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, ValueError is raised. The default for depth is ... | In Python you can debug a program calling the `breakpoint` built-in function. |
3,966,146 | On our production server we need to split 900k images into different dirs and update 400k rows (MySQL with InnoDB engine). I wrote a python script which goes through next steps:
1. Select small chunk of data from db (10 rows)
- Make new dirs
- Copy files to the created dirs and rename it
- Update db (there are some tr... | 2010/10/19 | [
"https://Stackoverflow.com/questions/3966146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/228012/"
] | What I recommend.
1. Add an `isProcessed` column to your table.
2. Make your script work on a chunk of, say, 1k rows for the first run (of course select only rows that are not processed).
3. Benchmark it.
4. Adjust the chunk size if needed.
5. Build another script that calls this one at intervals.
Don't forget to ad... | ```
db_data = db.query('''
SELECT id AS news_id, image AS src_filename
FROM emd_news
ORDER BY id ASC
LIMIT %s, %s''', offset, LIMIT_ROW_COUNT)
# Why is there any code here at all? If there's no data, why proceed?
if not db_data: break
``` |
3,966,146 | On our production server we need to split 900k images into different dirs and update 400k rows (MySQL with InnoDB engine). I wrote a python script which goes through next steps:
1. Select small chunk of data from db (10 rows)
- Make new dirs
- Copy files to the created dirs and rename it
- Update db (there are some tr... | 2010/10/19 | [
"https://Stackoverflow.com/questions/3966146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/228012/"
] | i will Add:
Why you create in each loop a new connexion and close it heh !!!
And maybe you can use db.autocommit(False) specially for the UPDATE and do a db.commit() for each 100 rows or something ;
and like Alin Purcaru you should do some benchmark as well.
Hope this can help :) | ```
db_data = db.query('''
SELECT id AS news_id, image AS src_filename
FROM emd_news
ORDER BY id ASC
LIMIT %s, %s''', offset, LIMIT_ROW_COUNT)
# Why is there any code here at all? If there's no data, why proceed?
if not db_data: break
``` |
32,506,956 | I am doing ex47 in Learning Python the Hard W[enter link description here](http://learnpythonthehardway.org/book/ex47.html)ay.
My problem here is that I am unable to import a module `from ex47.game.py import Room` from the other file in the following code:
```
from nose.tools import *
from ex47.game.py import Room
... | 2015/09/10 | [
"https://Stackoverflow.com/questions/32506956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1427176/"
] | I just went through this exercises right now and since I wanted a bit more explanation I've searched on the internet and found this post... hence my late response.. but I hope this helps if someone else encounter this problem.
He is not really clear about the structure of your Directory. So you should have a **ex47** ... | `export PYTHONPATH=.` adds current directory to the list of paths that python will search when looking for a module.
That is, current directory at the time of the search, not the time you enter the line.
But, as you run your programe from `skeleton`, that will make python search for `ex47.game` in the `skeleton` direc... |
32,506,956 | I am doing ex47 in Learning Python the Hard W[enter link description here](http://learnpythonthehardway.org/book/ex47.html)ay.
My problem here is that I am unable to import a module `from ex47.game.py import Room` from the other file in the following code:
```
from nose.tools import *
from ex47.game.py import Room
... | 2015/09/10 | [
"https://Stackoverflow.com/questions/32506956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1427176/"
] | I just went through this exercises right now and since I wanted a bit more explanation I've searched on the internet and found this post... hence my late response.. but I hope this helps if someone else encounter this problem.
He is not really clear about the structure of your Directory. So you should have a **ex47** ... | As far as I know.... when you do import in python, you must not to include .py extension.
```
from ex47.game.py import Room
```
should have coded this instead:
```
from ex47.game import Room
```
where game.py was saved in the folder ex47. I hope this clarify your question. |
71,640,992 | I have a list of headings and subheadings of a document.
```
test_list = ['heading', 'heading','sub-heading', 'sub-heading', 'heading', 'sub-heading', 'sub-sub-heading', 'sub-sub-heading', 'sub-heading', 'sub-heading', 'sub-sub-heading', 'sub-sub-heading','sub-sub-heading', 'heading']
```
I want to assign unique ind... | 2022/03/27 | [
"https://Stackoverflow.com/questions/71640992",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9669200/"
] | Those ghosts updates are a known, long standing issue, as evidenced by [this](https://github.com/hashicorp/terraform-provider-aws/issues/18311) still open, 3 year old issue on GH without a solution.
You can try updating your TF, as 0.13 is a very old version. You can also setup [ignore\_changes](https://www.terraform.... | I encountered a similar thing when upgrading Aurora mysql from 5.6 to 5.7: `log_output` re-appeared in every plan output.
However, the configured value in the default paramater group changed from 5.6 to 5.7 (from TABLE to FILE). I suspect since there was no change, AWS API returns empty, TF state is not updated, repea... |
70,078,645 | I have written the following python code to read in XYZ data as CSV and then grid to a GTiff format.
When I run the code I am getting no errors.
However, after trying to debug, I added some print statements and noticed that the functions aren't actually being called.
How can I run this script so that it all complete... | 2021/11/23 | [
"https://Stackoverflow.com/questions/70078645",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15310475/"
] | Use
```
if __name__ == "__main__":
app = gdal_toolbox(kwargs)
app.run()
```
or
```
if __name__ == "__main__":
gdal_toolbox(kwargs).run()
```
Use thease codes at the end of your script.
And the solution is :
```
class gdal_toolbox:
## CONSTANTS ##
def __init__( self, kwargs ):
prin... | It seems like you are not executing anything in this piece of code, just defining class and functions within it, right? |
58,822,095 | I have a problem using pyarrow.orc module in Anaconda on Windows 10.
```
import pyarrow.orc as orc
```
throws an exception:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\apps\Anaconda3\envs\ws\lib\site-packages\pyarrow\orc.py", line 23, in <module>
import pyarrow._orc a... | 2019/11/12 | [
"https://Stackoverflow.com/questions/58822095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12361891/"
] | The ORC reader is not supported at all on Windows and has never been to my knowledge. Apache ORC in C++ is not known to build yet with the Visual Studio C++ compiler. | Bottom line up front,
I had the same error. This was the solution for me:
```
!pip install pyarrow==0.13.0
```
I'm not sure this is limited to Windows 10, I am getting the same error in AWS Sagemaker in the last few days. This was working fine before, on a previous Sagemaker instance.
Using the Conda Packages menu... |
58,822,095 | I have a problem using pyarrow.orc module in Anaconda on Windows 10.
```
import pyarrow.orc as orc
```
throws an exception:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\apps\Anaconda3\envs\ws\lib\site-packages\pyarrow\orc.py", line 23, in <module>
import pyarrow._orc a... | 2019/11/12 | [
"https://Stackoverflow.com/questions/58822095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12361891/"
] | The ORC reader is not supported at all on Windows and has never been to my knowledge. Apache ORC in C++ is not known to build yet with the Visual Studio C++ compiler. | Below Code solve my issue on windows. Need to install pyorc . It worked well with plain python ,no conda needed. Please refer video <https://www.youtube.com/watch?v=qvV_Frc6zB8> by Alfred Zhong. He nicely explain it.
```
import pyorc
import pandas as pd
data = open('file1.orc','rb')
reader = pyorc.Reader(data)
column... |
67,928,883 | I'm working on this REST application in python `Flask` and a driver called `pymongo`. But if someone knows `mongodb` well he/she maybe able to answer my question.
Suppose Im inserting a new document in a collection say `students`. I want to get the whole inserted document as soon as the document is saved in the collec... | 2021/06/10 | [
"https://Stackoverflow.com/questions/67928883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12925831/"
] | Put the data to be inserted into a dictionary variable; on insert, the variable will have the `_id` added by pymongo.
```
from pymongo import MongoClient
db = MongoClient()['mydatabase']
doc = {
"name": "name"
}
db.students.insert_one(doc)
print(doc)
```
prints:
```
{'name': 'name', '_id': ObjectId('60ce419... | Unfortunately, the commenters are correct. The PyMongo pattern doesn't specifically allow for what you are asking. You are expected to just use the inserted\_id from the [result](https://pymongo.readthedocs.io/en/stable/api/pymongo/results.html#pymongo.results.InsertOneResult) and if you needed to get the full object f... |
52,501,105 | I am trying to connect to MSSQL with help of django-pyodbc. I have installed all the required packages like FreeTDS, unixODBC and django-pyodbc. When I connect using tsql and isql I am able to connect:-
```
>tsql -S mssql -U ********* -P ***********
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default chars... | 2018/09/25 | [
"https://Stackoverflow.com/questions/52501105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2034743/"
] | This has to do with the current scope that Rankx evaluates de Aggregation.
Try wrapping your aggregation with CALCULATE, and you probably want the SUM not the MAX:
```
Rank Reseller = RANKX(ALL(ResellerSales), CALCULATE(SUM(ResellerSales[SalesAmount])))
```
You can create a Measure like so, and use it on RANKX, sin... | To rank the [ReSellerkey] by [SalesAmount] you'd want to do something like this:
```
Rank Sales Amount :=
RANKX(
'Table',
'Table'[SalesAmount],
,
ASC,
Dense
)
``` |
42,301,458 | I have a large netcdf file which is three dimensional. I want to replace for the variable `LU_INDEX` in the netcdf file all the values 10 with 2.
I wrote this python script to do so but it does not seem to work.
```
filelocation = 'D:/dataset.nc'
ncdataset = nc.Dataset(filelocation,'r')
lat = ncdataset.v... | 2017/02/17 | [
"https://Stackoverflow.com/questions/42301458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581459/"
] | You might try [NCO](http://nco.sf.net/nco.html#ncap2)
```
ncap2 -s 'where(LU_INDEX == 10) LU_INDEX=2' in.nc out.nc
``` | I worked it out as follow:
```
import netCDF4 as nc
import numpy as np
pathname = 'D:'
filename = '%s/dataset.nc'%pathname
ncfile = nc.Dataset(filename,'r+')
lu_index = ncfile.variables['LU_INDEX'][:]
I = np.where(lu_index == 10)
lu_index[I] = 2
ncfile.variables['LU_INDEX'][:] = lu_index
filename.close()
print 'conv... |
42,301,458 | I have a large netcdf file which is three dimensional. I want to replace for the variable `LU_INDEX` in the netcdf file all the values 10 with 2.
I wrote this python script to do so but it does not seem to work.
```
filelocation = 'D:/dataset.nc'
ncdataset = nc.Dataset(filelocation,'r')
lat = ncdataset.v... | 2017/02/17 | [
"https://Stackoverflow.com/questions/42301458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581459/"
] | You might try [NCO](http://nco.sf.net/nco.html#ncap2)
```
ncap2 -s 'where(LU_INDEX == 10) LU_INDEX=2' in.nc out.nc
``` | using np.array might not work for a very large dataset with the following error
"ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size."
CDO can be a nice tool other than NCO and for me, it is much fast.
```
CDO setvals,10,2 in.nc out.nc
```
It is particularly fast ... |
25,811,202 | I am trying to execute a shell command and kill it using python **signal** module.
I know signals work only with main thread, so I run the Django development server with,
```
python manage.py runserver --nothreading --noreload
```
and it works fine.
But when i deploy the django application with Apache/mod\_wsgi, i... | 2014/09/12 | [
"https://Stackoverflow.com/questions/25811202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2102830/"
] | are you running with DEBUG enabled in setting.py ?
If yes try disabling it to see if the issue persists. | I'm not sure that can be done that easily, or at least not with mod\_wsgi. The decision to thread or not to thread is the sum of build and run time options in both apache and mod\_wsgi, which are both set by default, to threading.
I would point you to the docs about that, but I can only post two links, so I think it's... |
64,512,500 | Arrays of labels of objects and distances to that objects are given. I want to apply knn to find the label of prediction. I want to use `np.bincount` for that. However, I don't understand how to use this.
See some example
```
labels = [[1,1,2,0,0,3,3,3,5,1,3],
[1,1,2,0,0,3,3,3,5,1,3]]
weights= [[0,0,0,0,0,0... | 2020/10/24 | [
"https://Stackoverflow.com/questions/64512500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13184183/"
] | The next solution gives me desired result:
```
labels = [[1,1,2,0,0,3,3,3,5,1,3],
[1,1,2,0,0,3,3,3,5,1,3]]
weights= [[0,0,0,0,0,0,0,0,1,0,0],
[0,0,0,0,0,0,0,0,1,0,0]]
length = len(labels[0])
lab_weight = np.hstack((labels, weights))
predict = np.apply_along_axis(lambda x: np.bincount(x[:length], ... | The problem with your code is that you attempt to use your
function to **2-D** slices of your array, whereas *apply\_along\_axis*
applies the given function to **1-D** slices.
So your code generates an exception: *ValueError: object of too small
depth for desired array*.
To apply your function to 2-D slices, use a li... |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | Here is a solution that doesn't require code changes:
```
python -m pdb prog.py <prog_args>
(pdb) b 3
Breakpoint 1 at prog.py:3
(pdb) c
...
(pdb) p a
5
(pdb) a=7
(pdb) ...
```
In short:
* start your program under debugger control
* set a break point at a given line of code
* let the program run up to that point
* y... | Not sure what the real question is. Python gives you the 'pdb' debugger (google yourself) and in addition you can add logging and debug output as needed. |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | <http://docs.python.org/library/pdb.html>
```
import pdb
pdb.set_trace()
``` | Here is a solution that doesn't require code changes:
```
python -m pdb prog.py <prog_args>
(pdb) b 3
Breakpoint 1 at prog.py:3
(pdb) c
...
(pdb) p a
5
(pdb) a=7
(pdb) ...
```
In short:
* start your program under debugger control
* set a break point at a given line of code
* let the program run up to that point
* y... |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | Python `3.7` has a new builtin way of setting breakpoints.
```
breakpoint()
```
The implementation of `breakpoint()` will `import pdb` and call `pdb.set_trace()`.
Remember to include the braces `()`, since `breakpoint` is a function, not a keyword. | Not sure what the real question is. Python gives you the 'pdb' debugger (google yourself) and in addition you can add logging and debug output as needed. |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | A *one-line* partial solution is simply to put `1/0` where you want the breakpoint: this will raise an exception, which will be caught by the debugger. Two advantages of this approach are:
* Breakpoints set this way are robust against code modification (no dependence on a particular line number);
* One does not need t... | Not sure what the real question is. Python gives you the 'pdb' debugger (google yourself) and in addition you can add logging and debug output as needed. |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | Here is a solution that doesn't require code changes:
```
python -m pdb prog.py <prog_args>
(pdb) b 3
Breakpoint 1 at prog.py:3
(pdb) c
...
(pdb) p a
5
(pdb) a=7
(pdb) ...
```
In short:
* start your program under debugger control
* set a break point at a given line of code
* let the program run up to that point
* y... | Python `3.7` has a new builtin way of setting breakpoints.
```
breakpoint()
```
The implementation of `breakpoint()` will `import pdb` and call `pdb.set_trace()`.
Remember to include the braces `()`, since `breakpoint` is a function, not a keyword. |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | You can run the program using pdb, and add breakpoints before starting execution.
In reality though, it's usually just as fast to edit the code and put in the set\_trace() call, as another user stated. | Not sure what the real question is. Python gives you the 'pdb' debugger (google yourself) and in addition you can add logging and debug output as needed. |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | <http://docs.python.org/library/pdb.html>
```
import pdb
pdb.set_trace()
``` | A *one-line* partial solution is simply to put `1/0` where you want the breakpoint: this will raise an exception, which will be caught by the debugger. Two advantages of this approach are:
* Breakpoints set this way are robust against code modification (no dependence on a particular line number);
* One does not need t... |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | <http://docs.python.org/library/pdb.html>
```
import pdb
pdb.set_trace()
``` | You can run the program using pdb, and add breakpoints before starting execution.
In reality though, it's usually just as fast to edit the code and put in the set\_trace() call, as another user stated. |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | Python `3.7` has a new builtin way of setting breakpoints.
```
breakpoint()
```
The implementation of `breakpoint()` will `import pdb` and call `pdb.set_trace()`.
Remember to include the braces `()`, since `breakpoint` is a function, not a keyword. | You can run the program using pdb, and add breakpoints before starting execution.
In reality though, it's usually just as fast to edit the code and put in the set\_trace() call, as another user stated. |
5,769,382 | I'm not sure if what I'm asking is possible at all, but since python is an interpreter it might be. I'm trying to make changes in an open-source project but because there are no types in python it's difficult to know what the variables have as data and what they do. You can't just look up the documentation on the var's... | 2011/04/24 | [
"https://Stackoverflow.com/questions/5769382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492336/"
] | Here is a solution that doesn't require code changes:
```
python -m pdb prog.py <prog_args>
(pdb) b 3
Breakpoint 1 at prog.py:3
(pdb) c
...
(pdb) p a
5
(pdb) a=7
(pdb) ...
```
In short:
* start your program under debugger control
* set a break point at a given line of code
* let the program run up to that point
* y... | You can run the program using pdb, and add breakpoints before starting execution.
In reality though, it's usually just as fast to edit the code and put in the set\_trace() call, as another user stated. |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | I have assumed that the elements of the string can be in any order and appear any number of times. For example, `'a foo'` should match and `'a foo b foo'` should not.
You can do that with a series of alternations employing lookaheads, one for each substring of interest, but it becomes a bit of a dog's breakfast when t... | If the order of the strings doesn't matter, and you want to make sure every string occurs only once, you can turn the list into a set in Python:
```
my_lst = ['a', 'a', 'b', 'c']
my_set = set(lst)
print(my_set)
# {'a', 'c', 'b'}
``` |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | You may use this regex with a capture group and a negative lookahead:
For `Perl`, you can use this variant with [forward referencing](https://www.regular-expressions.info/backref2.html):
```sh
^foo((?!.*\1) [abc])+$
```
[RegEx Demo](https://regex101.com/r/P9Qp9r/2)
**RegEx Details:**
* `^`: Start
* `foo`: Match `... | You can assert that there is no match for a second match for a space and a letter at the right:
```
foo(?!(?: [abc])*( [abc])(?: [abc])*\1)(?: [abc])*
```
* `foo` Match literally
* `(?!` Negative lookahead
+ `(?: [abc])*` Match optional repetitions of a space and a b or c
+ `( [abc])` Capture group, use to compare... |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | You may use this regex with a capture group and a negative lookahead:
For `Perl`, you can use this variant with [forward referencing](https://www.regular-expressions.info/backref2.html):
```sh
^foo((?!.*\1) [abc])+$
```
[RegEx Demo](https://regex101.com/r/P9Qp9r/2)
**RegEx Details:**
* `^`: Start
* `foo`: Match `... | Here is a modified version of anubhava's answer, using a [backreference](https://www.regular-expressions.info/backref.html) (which works in Python, and is easier to understand at least for me) instead of a forward reference.
Match using `[abc]` inside a capturing group, then check that the text matched by the capturi... |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | You can do it using references to previously captured groups.
```regex
foo(?: ([abc]))?(?: (?!\1)([abc]))?(?: (?!\1|\2)([abc]))?$
```
This gets quite long with many options. Such a regex can be generated dynamically, if necessary.
```py
def match_sequence_without_repeats(options, seperator):
def prevent_previou... | There is not much to add to the above answers except here is a regex that does not use back or forward references. Instead it uses 3 separate negative lookahead assertions to ensure that the input does not contain 2 occurrences of either `a` or `b` or `c`. The regex also allows for liberal uses of spaces.
```
^foo(?![... |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | Here is a modified version of anubhava's answer, using a [backreference](https://www.regular-expressions.info/backref.html) (which works in Python, and is easier to understand at least for me) instead of a forward reference.
Match using `[abc]` inside a capturing group, then check that the text matched by the capturi... | If the order of the strings doesn't matter, and you want to make sure every string occurs only once, you can turn the list into a set in Python:
```
my_lst = ['a', 'a', 'b', 'c']
my_set = set(lst)
print(my_set)
# {'a', 'c', 'b'}
``` |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | If it doesn't have to be a regex:
```py
import collections
# python >=3.10
def is_a_match(sentence):
words = sentence.split()
return (
(len(words) > 0)
and (words[0] == 'foo')
and (collections.Counter(words) <= collections.Counter(['foo', 'a', 'b', 'c']))
)
# python <3.10
def is_a_match... | If the order of the strings doesn't matter, and you want to make sure every string occurs only once, you can turn the list into a set in Python:
```
my_lst = ['a', 'a', 'b', 'c']
my_set = set(lst)
print(my_set)
# {'a', 'c', 'b'}
``` |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | I have assumed that the elements of the string can be in any order and appear any number of times. For example, `'a foo'` should match and `'a foo b foo'` should not.
You can do that with a series of alternations employing lookaheads, one for each substring of interest, but it becomes a bit of a dog's breakfast when t... | There is not much to add to the above answers except here is a regex that does not use back or forward references. Instead it uses 3 separate negative lookahead assertions to ensure that the input does not contain 2 occurrences of either `a` or `b` or `c`. The regex also allows for liberal uses of spaces.
```
^foo(?![... |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | You can assert that there is no match for a second match for a space and a letter at the right:
```
foo(?!(?: [abc])*( [abc])(?: [abc])*\1)(?: [abc])*
```
* `foo` Match literally
* `(?!` Negative lookahead
+ `(?: [abc])*` Match optional repetitions of a space and a b or c
+ `( [abc])` Capture group, use to compare... | I have assumed that the elements of the string can be in any order and appear any number of times. For example, `'a foo'` should match and `'a foo b foo'` should not.
You can do that with a series of alternations employing lookaheads, one for each substring of interest, but it becomes a bit of a dog's breakfast when t... |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | You can assert that there is no match for a second match for a space and a letter at the right:
```
foo(?!(?: [abc])*( [abc])(?: [abc])*\1)(?: [abc])*
```
* `foo` Match literally
* `(?!` Negative lookahead
+ `(?: [abc])*` Match optional repetitions of a space and a b or c
+ `( [abc])` Capture group, use to compare... | Here is a modified version of anubhava's answer, using a [backreference](https://www.regular-expressions.info/backref.html) (which works in Python, and is easier to understand at least for me) instead of a forward reference.
Match using `[abc]` inside a capturing group, then check that the text matched by the capturi... |
69,486,648 | I'm wondering if there's any way in python or perl to build a regex where you can define a set of options can appear at most once in any order. So for example I would like a derivative of `foo(?: [abc])*`, where `a`, `b`, `c` could only appear once. So:
```
foo a b c
foo b c a
foo a b
foo b
```
would all be valid, b... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69486648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710344/"
] | You may use this regex with a capture group and a negative lookahead:
For `Perl`, you can use this variant with [forward referencing](https://www.regular-expressions.info/backref2.html):
```sh
^foo((?!.*\1) [abc])+$
```
[RegEx Demo](https://regex101.com/r/P9Qp9r/2)
**RegEx Details:**
* `^`: Start
* `foo`: Match `... | There is not much to add to the above answers except here is a regex that does not use back or forward references. Instead it uses 3 separate negative lookahead assertions to ensure that the input does not contain 2 occurrences of either `a` or `b` or `c`. The regex also allows for liberal uses of spaces.
```
^foo(?![... |
2,313,032 | I am trying to create a regex that matches a US state abbreviations in a string using python.
The abbreviation can be in the format:
```
CA
Ca
```
The string could be:
```
Boulder, CO 80303
Boulder, Co
Boulder CO
...
```
Here is what I have, which obviously doesn't work that well. I'm not very good with regular... | 2010/02/22 | [
"https://Stackoverflow.com/questions/2313032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/74474/"
] | A simple and reliable way is to have all the states listed:
```
states = ['IA', 'KS', 'UT', 'VA', 'NC', 'NE', 'SD', 'AL', 'ID', 'FM', 'DE', 'AK', 'CT', 'PR', 'NM', 'MS', 'PW', 'CO', 'NJ', 'FL', 'MN', 'VI', 'NV', 'AZ', 'WI', 'ND', 'PA', 'OK', 'KY', 'RI', 'NH', 'MO', 'ME', 'VT', 'GA', 'GU', 'AS', 'NY', 'CA', 'HI', 'IL',... | ```
re.search(r'\b[a-z]{2}\b', subject, re.I)
```
it will find double-letter names of towns, though |
42,244,819 | My objective is to insert a key value pair in a YAML file which might be empty.
For example, my `hiera.yaml` (used in puppet) file contains only three hyphens.
Here is my code:
```
#!/usr/bin/python
import ruamel.yaml
import sys
def read_file(f):
with open(f, 'r') as yaml:
return ruamel.yaml.round_trip_load(y... | 2017/02/15 | [
"https://Stackoverflow.com/questions/42244819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7543970/"
] | If you indeed want to get all the data into a single string you can do it using collect:
```
val rows = df.select("defectDescription").collect().map(_.getString(0)).mkString(" ")
```
You first select the relevant column (so you have just it) and collect it, it would give you an array of rows. the map turns each row ... | ```
val str1 = df.select("defectDescription").collect.mkString(",")
val str = str1.replaceAll("[\\[\\]]","")
```
Another way to do this is as follows:
The 1st line selects the particular columns then collects the subset, collects behaves as:
Collect (Action) - Return all the elements of the dataset as an array at t... |
42,244,819 | My objective is to insert a key value pair in a YAML file which might be empty.
For example, my `hiera.yaml` (used in puppet) file contains only three hyphens.
Here is my code:
```
#!/usr/bin/python
import ruamel.yaml
import sys
def read_file(f):
with open(f, 'r') as yaml:
return ruamel.yaml.round_trip_load(y... | 2017/02/15 | [
"https://Stackoverflow.com/questions/42244819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7543970/"
] | If you indeed want to get all the data into a single string you can do it using collect:
```
val rows = df.select("defectDescription").collect().map(_.getString(0)).mkString(" ")
```
You first select the relevant column (so you have just it) and collect it, it would give you an array of rows. the map turns each row ... | ```
df.createTempView(viewName="table")
val res=spark.sqlContext.sql(sqlText="select defectDescription from table").collectAsList.toString.replace("[", "").replace("]", "")
```
Initially create a temporary view of the dataframe, then convert into a list, and then string- Finally remove the brackets as per the require... |
42,244,819 | My objective is to insert a key value pair in a YAML file which might be empty.
For example, my `hiera.yaml` (used in puppet) file contains only three hyphens.
Here is my code:
```
#!/usr/bin/python
import ruamel.yaml
import sys
def read_file(f):
with open(f, 'r') as yaml:
return ruamel.yaml.round_trip_load(y... | 2017/02/15 | [
"https://Stackoverflow.com/questions/42244819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7543970/"
] | If you indeed want to get all the data into a single string you can do it using collect:
```
val rows = df.select("defectDescription").collect().map(_.getString(0)).mkString(" ")
```
You first select the relevant column (so you have just it) and collect it, it would give you an array of rows. the map turns each row ... | Let's leverage parallel computing by not prematurely `collect`ing the data while there is associative processing to be done:
```
def str(r: Row) = r.getString(0)
def cat(r0: Row, r1: Row) = Row(s"${str(r0)} ${str(r1)}")
str(df.select("defectDescription").reduce(cat))
```
This allows parallel concatenations to be do... |
42,244,819 | My objective is to insert a key value pair in a YAML file which might be empty.
For example, my `hiera.yaml` (used in puppet) file contains only three hyphens.
Here is my code:
```
#!/usr/bin/python
import ruamel.yaml
import sys
def read_file(f):
with open(f, 'r') as yaml:
return ruamel.yaml.round_trip_load(y... | 2017/02/15 | [
"https://Stackoverflow.com/questions/42244819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7543970/"
] | ```
val str1 = df.select("defectDescription").collect.mkString(",")
val str = str1.replaceAll("[\\[\\]]","")
```
Another way to do this is as follows:
The 1st line selects the particular columns then collects the subset, collects behaves as:
Collect (Action) - Return all the elements of the dataset as an array at t... | Let's leverage parallel computing by not prematurely `collect`ing the data while there is associative processing to be done:
```
def str(r: Row) = r.getString(0)
def cat(r0: Row, r1: Row) = Row(s"${str(r0)} ${str(r1)}")
str(df.select("defectDescription").reduce(cat))
```
This allows parallel concatenations to be do... |
42,244,819 | My objective is to insert a key value pair in a YAML file which might be empty.
For example, my `hiera.yaml` (used in puppet) file contains only three hyphens.
Here is my code:
```
#!/usr/bin/python
import ruamel.yaml
import sys
def read_file(f):
with open(f, 'r') as yaml:
return ruamel.yaml.round_trip_load(y... | 2017/02/15 | [
"https://Stackoverflow.com/questions/42244819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7543970/"
] | ```
df.createTempView(viewName="table")
val res=spark.sqlContext.sql(sqlText="select defectDescription from table").collectAsList.toString.replace("[", "").replace("]", "")
```
Initially create a temporary view of the dataframe, then convert into a list, and then string- Finally remove the brackets as per the require... | Let's leverage parallel computing by not prematurely `collect`ing the data while there is associative processing to be done:
```
def str(r: Row) = r.getString(0)
def cat(r0: Row, r1: Row) = Row(s"${str(r0)} ${str(r1)}")
str(df.select("defectDescription").reduce(cat))
```
This allows parallel concatenations to be do... |
60,311,694 | I'm taking a look at some parser combinator libraries in Python ([Parsy](https://parsy.readthedocs.io/en/latest/index.html) to be more precise) and I'm currently faced with the following problem, simplified with a minimally working example below:
```py
text = '''
AAAAAAAAAA AAAAAAAA AAAAAAAAAAAAAA
BBBBBBB START THE TE... | 2020/02/20 | [
"https://Stackoverflow.com/questions/60311694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4614840/"
] | There was an issue related to the routing in the application. I had a parser inside the controller that was used for directing correct routes between a route "aluno" with first Param.
Once I had taken the route with no params and put it first at the controller, there was no need anymore for the parser, and the issue w... | Please check your method result type of controller
Change this:
```
@Contoller()
export class MyController {
// ...
async myMethod() {
return {}
}
}
```
to:
```
@Contoller()
export class MyController {
// ...
async myMethod():Promise<any> {
return {}
}
}
``` |
27,708,882 | I have two Anaconda installations on my computer. The first one is based on Python 2.7 and the other is based on Python 3.4. The default Python version is the 3.4 though. What is more, I can start Python 3.4 either by typing **/home/eualin/.bin/anaconda3/bin/python** or just **python**. I can do the same but for Python... | 2014/12/30 | [
"https://Stackoverflow.com/questions/27708882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/706838/"
] | You don't need multiple `anaconda` distributions for different python versions. I would suggest keeping only one.
`conda` basically lets you create environments for your different needs.
`conda create -n myenv python=3.3` creates a new environment named `myenv`, which works with a python3.3 interpreter.
`source acti... | Using virtualenv is your best option as @Dettorer has mentioned.
I found this method of installing and using virtualenv the most useful.
Check it out:
[Proper way to install virtualenv](https://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python) |
27,708,882 | I have two Anaconda installations on my computer. The first one is based on Python 2.7 and the other is based on Python 3.4. The default Python version is the 3.4 though. What is more, I can start Python 3.4 either by typing **/home/eualin/.bin/anaconda3/bin/python** or just **python**. I can do the same but for Python... | 2014/12/30 | [
"https://Stackoverflow.com/questions/27708882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/706838/"
] | You don't need multiple `anaconda` distributions for different python versions. I would suggest keeping only one.
`conda` basically lets you create environments for your different needs.
`conda create -n myenv python=3.3` creates a new environment named `myenv`, which works with a python3.3 interpreter.
`source acti... | Virtualenv seems like the obvious answer here, but I do want to suggest an alternative that we've been using to great effect lately: [Fig](http://www.fig.sh/) - this is particularly effective since we use Docker in production as well, but I imagine that using Fig as a replacement for virtualenv would be quite effective... |
27,708,882 | I have two Anaconda installations on my computer. The first one is based on Python 2.7 and the other is based on Python 3.4. The default Python version is the 3.4 though. What is more, I can start Python 3.4 either by typing **/home/eualin/.bin/anaconda3/bin/python** or just **python**. I can do the same but for Python... | 2014/12/30 | [
"https://Stackoverflow.com/questions/27708882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/706838/"
] | Virtualenv seems like the obvious answer here, but I do want to suggest an alternative that we've been using to great effect lately: [Fig](http://www.fig.sh/) - this is particularly effective since we use Docker in production as well, but I imagine that using Fig as a replacement for virtualenv would be quite effective... | Using virtualenv is your best option as @Dettorer has mentioned.
I found this method of installing and using virtualenv the most useful.
Check it out:
[Proper way to install virtualenv](https://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python) |
18,730,612 | I want to run both a websocket and a flash policy file server on port 80 using Tornado. The reason for not wanting to run a server on the default port 843 is that it's often closed in corporate networks. Is it possible to do this and if so, how should I do this?
I tried the following structure, which does not seem to ... | 2013/09/10 | [
"https://Stackoverflow.com/questions/18730612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2259361/"
] | the new formula become L= P / [(1+c)^n-1]/[c(1+c)^n]
let me work this out for you. To add L to the other side you have to multiple by 1/L. so now the left side of the equation is P/L. to get rid of the P you have to multiple 1/P. now leaving the L alone makes the L into a ratio of 1/L. To get rid of the one you have ... | Your monthly payment isn't being calculated correctly in the code that isn't working properly. If you look at it, you'll see that you're not factoring in your debts whatsoever.
I'm not sure exactly how you're choosing to calculate the monthly payment, but my guess is you need to subtract your debts from your income an... |
18,730,612 | I want to run both a websocket and a flash policy file server on port 80 using Tornado. The reason for not wanting to run a server on the default port 843 is that it's often closed in corporate networks. Is it possible to do this and if so, how should I do this?
I tried the following structure, which does not seem to ... | 2013/09/10 | [
"https://Stackoverflow.com/questions/18730612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2259361/"
] | the new formula become L= P / [(1+c)^n-1]/[c(1+c)^n]
let me work this out for you. To add L to the other side you have to multiple by 1/L. so now the left side of the equation is P/L. to get rid of the P you have to multiple 1/P. now leaving the L alone makes the L into a ratio of 1/L. To get rid of the one you have ... | Semi-Solved:
The issue was with my formula and a colleague and I figured out the major problem. When I converted the original formula (which I didn't outline in very good detail here), I didn't perform the proper algebraic method of reversing what was done to one side of the equation on the other side. Basically, the ... |
25,514,378 | This sample python program:
```
document='''<p>This is <i>something</i>, it happens
in <b>real</b> life</p>'''
from bs4 import BeautifulSoup
soup = BeautifulSoup(document)
print(soup.prettify())
```
produces the following output:
```
<html>
<body>
<p>
This is
<i>
something
</i>
, i... | 2014/08/26 | [
"https://Stackoverflow.com/questions/25514378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1538701/"
] | Beautiful Soup's `.prettify()` method is defined as outputting each tag on its own line (<http://www.crummy.com/software/BeautifulSoup/bs4/doc/index.html#pretty-printing>). If you want something else you'll need to make it yourself by walking the parse tree. | As previous comments and thebjorn stated, BeautifulSoup's definition of pretty html is with each tag on it's own line, however, to deal with some of your problems with the spacing of , and such, you can collapse it first like so:
```
from bs4 import BeautifulSoup
document = """<p>This is <i>something</i>, it happens... |
25,514,378 | This sample python program:
```
document='''<p>This is <i>something</i>, it happens
in <b>real</b> life</p>'''
from bs4 import BeautifulSoup
soup = BeautifulSoup(document)
print(soup.prettify())
```
produces the following output:
```
<html>
<body>
<p>
This is
<i>
something
</i>
, i... | 2014/08/26 | [
"https://Stackoverflow.com/questions/25514378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1538701/"
] | Because of the habit of `.prettify` to put each tag in it's own line, it is not suitable for production code; it is only usable for debugging output, IMO. Just convert your soup to a string, using the `str` builtin function.
What you want is a change of the string contents in your tree; you could create a function to ... | As previous comments and thebjorn stated, BeautifulSoup's definition of pretty html is with each tag on it's own line, however, to deal with some of your problems with the spacing of , and such, you can collapse it first like so:
```
from bs4 import BeautifulSoup
document = """<p>This is <i>something</i>, it happens... |
14,281,469 | So I've got these huge text files that are filled with a single comma delimited record per line. I need a way to process the files line by line, removing lines that meet certain criteria. Some of the removals are easy, such as one of the fields is less than a certain length. The hardest criteria is that these lines all... | 2013/01/11 | [
"https://Stackoverflow.com/questions/14281469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/947756/"
] | Reading all the rows in is not ideal, because you need to store the whole lot in memory.
Instead you could read line by line, writing out the records that you want to keep as you go. You could keep a cache of the rows you've hit previously, bounded to be within 15 seconds of the current program. In very rough pseudo-c... | You might read the file and output just the line numbers to be deleted (to be sorted and used in a separate pass.) Your hash map could then contain just the minimum data needed plus the line number. This could save a lot of memory if the data needed is small compared to the line size. |
32,054,066 | I'm using the [`websockets`](https://github.com/aaugustin/websockets) library to create a websocket server in Python 3.4. Here's a simple echo server:
```python
import asyncio
import websockets
@asyncio.coroutine
def connection_handler(websocket, path):
while True:
msg = yield from websocket.recv()
... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1668646/"
] | **TL;DR** Use [`asyncio.ensure_future()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.ensure_future) to run several coroutines concurrently.
---
>
> Maybe this scenario requires a framework based on events/callbacks rather than one based on coroutines? Tornado?
>
>
>
No, you don't need any other ... | Same issue, can hardly got solution until I saw the perfect sample here: <http://websockets.readthedocs.io/en/stable/intro.html#both>
```
done, pending = await asyncio.wait(
[listener_task, producer_task],
return_when=asyncio.FIRST_COMPLETED) # Important
```
So, I can handle multi coroutine tasks s... |
32,054,066 | I'm using the [`websockets`](https://github.com/aaugustin/websockets) library to create a websocket server in Python 3.4. Here's a simple echo server:
```python
import asyncio
import websockets
@asyncio.coroutine
def connection_handler(websocket, path):
while True:
msg = yield from websocket.recv()
... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1668646/"
] | **TL;DR** Use [`asyncio.ensure_future()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.ensure_future) to run several coroutines concurrently.
---
>
> Maybe this scenario requires a framework based on events/callbacks rather than one based on coroutines? Tornado?
>
>
>
No, you don't need any other ... | I'm surprised `gather` isn't mentioned.
From the [Python documentation](https://docs.python.org/3/library/asyncio-task.html#asyncio.gather):
```
import asyncio
async def factorial(name, number):
f = 1
for i in range(2, number + 1):
print(f"Task {name}: Compute factorial({i})...")
await asynci... |
32,054,066 | I'm using the [`websockets`](https://github.com/aaugustin/websockets) library to create a websocket server in Python 3.4. Here's a simple echo server:
```python
import asyncio
import websockets
@asyncio.coroutine
def connection_handler(websocket, path):
while True:
msg = yield from websocket.recv()
... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1668646/"
] | **TL;DR** Use [`asyncio.ensure_future()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.ensure_future) to run several coroutines concurrently.
---
>
> Maybe this scenario requires a framework based on events/callbacks rather than one based on coroutines? Tornado?
>
>
>
No, you don't need any other ... | If you are using *Python 3.7 and later* you can use `asyncio.gather()` and `asyncio.run()` as follows:
```py
import asyncio
async def coro1():
for i in range(1, 6):
print(i)
await asyncio.sleep(0) # switches task every one iteration.
async def coro2():
for i in range(1, 6):
print(i *... |
32,054,066 | I'm using the [`websockets`](https://github.com/aaugustin/websockets) library to create a websocket server in Python 3.4. Here's a simple echo server:
```python
import asyncio
import websockets
@asyncio.coroutine
def connection_handler(websocket, path):
while True:
msg = yield from websocket.recv()
... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1668646/"
] | I'm surprised `gather` isn't mentioned.
From the [Python documentation](https://docs.python.org/3/library/asyncio-task.html#asyncio.gather):
```
import asyncio
async def factorial(name, number):
f = 1
for i in range(2, number + 1):
print(f"Task {name}: Compute factorial({i})...")
await asynci... | Same issue, can hardly got solution until I saw the perfect sample here: <http://websockets.readthedocs.io/en/stable/intro.html#both>
```
done, pending = await asyncio.wait(
[listener_task, producer_task],
return_when=asyncio.FIRST_COMPLETED) # Important
```
So, I can handle multi coroutine tasks s... |
32,054,066 | I'm using the [`websockets`](https://github.com/aaugustin/websockets) library to create a websocket server in Python 3.4. Here's a simple echo server:
```python
import asyncio
import websockets
@asyncio.coroutine
def connection_handler(websocket, path):
while True:
msg = yield from websocket.recv()
... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1668646/"
] | Same issue, can hardly got solution until I saw the perfect sample here: <http://websockets.readthedocs.io/en/stable/intro.html#both>
```
done, pending = await asyncio.wait(
[listener_task, producer_task],
return_when=asyncio.FIRST_COMPLETED) # Important
```
So, I can handle multi coroutine tasks s... | If you are using *Python 3.7 and later* you can use `asyncio.gather()` and `asyncio.run()` as follows:
```py
import asyncio
async def coro1():
for i in range(1, 6):
print(i)
await asyncio.sleep(0) # switches task every one iteration.
async def coro2():
for i in range(1, 6):
print(i *... |
32,054,066 | I'm using the [`websockets`](https://github.com/aaugustin/websockets) library to create a websocket server in Python 3.4. Here's a simple echo server:
```python
import asyncio
import websockets
@asyncio.coroutine
def connection_handler(websocket, path):
while True:
msg = yield from websocket.recv()
... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1668646/"
] | I'm surprised `gather` isn't mentioned.
From the [Python documentation](https://docs.python.org/3/library/asyncio-task.html#asyncio.gather):
```
import asyncio
async def factorial(name, number):
f = 1
for i in range(2, number + 1):
print(f"Task {name}: Compute factorial({i})...")
await asynci... | If you are using *Python 3.7 and later* you can use `asyncio.gather()` and `asyncio.run()` as follows:
```py
import asyncio
async def coro1():
for i in range(1, 6):
print(i)
await asyncio.sleep(0) # switches task every one iteration.
async def coro2():
for i in range(1, 6):
print(i *... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | It doesn't copy anything. It's just that assigning to `self.curstack` does not modify whatever `self.curstack` used to refer to. It just makes `self.curstack` refer to something else.
Think of it this way. `self.curstack` points to some stuff. With `objs = self.curstack` you make `objs` point to that same stuff. With ... | Python uses references everywhere. So your code works like this:
```
objs = self.curstack
```
Now `objs` points to whatever `curstack` was.
```
self.curstack = []
```
Now `curstack` points to an empty list. `objs` is unchanged, and points to the old `curstack`.
```
return objs
```
You return `objs`, which is t... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | It doesn't copy anything. It's just that assigning to `self.curstack` does not modify whatever `self.curstack` used to refer to. It just makes `self.curstack` refer to something else.
Think of it this way. `self.curstack` points to some stuff. With `objs = self.curstack` you make `objs` point to that same stuff. With ... | Let's demonstrate what's really going on (using `id` which shows the location of the memory)
```
a = [1,2,3]
print id(a)
b = a
print id(b)
a = 4
print id(a)
print a
print b
```
>
> 4339130240
>
>
> 4339130240
>
>
> 4298163184
>
>
> 4
>
>
> [1, 2, 3]
>
>
>
So `a` and `b` initially point to the same p... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | It doesn't copy anything. It's just that assigning to `self.curstack` does not modify whatever `self.curstack` used to refer to. It just makes `self.curstack` refer to something else.
Think of it this way. `self.curstack` points to some stuff. With `objs = self.curstack` you make `objs` point to that same stuff. With ... | As mentioned in all the answers that `self.curstack` doesn't modify it just refer to something. In you case it is referring to an empty list `[]`.
You can actually see the how objects are referring using [**swampy**](http://www.greenteapress.com/thinkpython/swampy/)
```
from swampy.Lumpy import Lumpy
class ref_tes... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | It doesn't copy anything. It's just that assigning to `self.curstack` does not modify whatever `self.curstack` used to refer to. It just makes `self.curstack` refer to something else.
Think of it this way. `self.curstack` points to some stuff. With `objs = self.curstack` you make `objs` point to that same stuff. With ... | In Python, there are two spaces, the namespace and the object space.
Names are just labels you assign to objects, which live in the object space. Objects have values and types; names are just there for our convenience; so that we may access things in the object space.
This is different than other languages like C whe... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | Python uses references everywhere. So your code works like this:
```
objs = self.curstack
```
Now `objs` points to whatever `curstack` was.
```
self.curstack = []
```
Now `curstack` points to an empty list. `objs` is unchanged, and points to the old `curstack`.
```
return objs
```
You return `objs`, which is t... | Let's demonstrate what's really going on (using `id` which shows the location of the memory)
```
a = [1,2,3]
print id(a)
b = a
print id(b)
a = 4
print id(a)
print a
print b
```
>
> 4339130240
>
>
> 4339130240
>
>
> 4298163184
>
>
> 4
>
>
> [1, 2, 3]
>
>
>
So `a` and `b` initially point to the same p... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | Python uses references everywhere. So your code works like this:
```
objs = self.curstack
```
Now `objs` points to whatever `curstack` was.
```
self.curstack = []
```
Now `curstack` points to an empty list. `objs` is unchanged, and points to the old `curstack`.
```
return objs
```
You return `objs`, which is t... | In Python, there are two spaces, the namespace and the object space.
Names are just labels you assign to objects, which live in the object space. Objects have values and types; names are just there for our convenience; so that we may access things in the object space.
This is different than other languages like C whe... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | As mentioned in all the answers that `self.curstack` doesn't modify it just refer to something. In you case it is referring to an empty list `[]`.
You can actually see the how objects are referring using [**swampy**](http://www.greenteapress.com/thinkpython/swampy/)
```
from swampy.Lumpy import Lumpy
class ref_tes... | Let's demonstrate what's really going on (using `id` which shows the location of the memory)
```
a = [1,2,3]
print id(a)
b = a
print id(b)
a = 4
print id(a)
print a
print b
```
>
> 4339130240
>
>
> 4339130240
>
>
> 4298163184
>
>
> 4
>
>
> [1, 2, 3]
>
>
>
So `a` and `b` initially point to the same p... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | In Python, there are two spaces, the namespace and the object space.
Names are just labels you assign to objects, which live in the object space. Objects have values and types; names are just there for our convenience; so that we may access things in the object space.
This is different than other languages like C whe... | Let's demonstrate what's really going on (using `id` which shows the location of the memory)
```
a = [1,2,3]
print id(a)
b = a
print id(b)
a = 4
print id(a)
print a
print b
```
>
> 4339130240
>
>
> 4339130240
>
>
> 4298163184
>
>
> 4
>
>
> [1, 2, 3]
>
>
>
So `a` and `b` initially point to the same p... |
27,812,789 | I read that the assign in python does not copy it works like it does in c where it assigns a pointer to an object.
But when I debug this function:
```
def popall(self):
objs = self.curstack
self.curstack = []
return objs
```
It looks like some kind of copy is taking place. After this function runs obis... | 2015/01/07 | [
"https://Stackoverflow.com/questions/27812789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2444342/"
] | As mentioned in all the answers that `self.curstack` doesn't modify it just refer to something. In you case it is referring to an empty list `[]`.
You can actually see the how objects are referring using [**swampy**](http://www.greenteapress.com/thinkpython/swampy/)
```
from swampy.Lumpy import Lumpy
class ref_tes... | In Python, there are two spaces, the namespace and the object space.
Names are just labels you assign to objects, which live in the object space. Objects have values and types; names are just there for our convenience; so that we may access things in the object space.
This is different than other languages like C whe... |
56,526,857 | I am developing a software in which I have an OpenGL window. I am creating the GUI of the software using `PyQt5` and for the opengGL Window I am using `QOpengGLWidget` and for object selection, I am using [**Stencil** **Buffer**](https://en.wikibooks.org/wiki/OpenGL_Programming/Object_selection) and reading **STENCIL\_... | 2019/06/10 | [
"https://Stackoverflow.com/questions/56526857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | `strip()` does not respect count or order when it removes characters from the end of your string. The argument you passed it, `"-Vaccines"`, contains an "a", so it will remove the "a" from "Rivera". It does not matter that it already removed an "a" from "Vaccines" and it does not matter that it doesn't come between a V... | The problem is that the argument to `strip` isn't used the way you think it is. The argument isn't treated as a sequence of characters, but rather as a set of characters. Any character in the argument string is removed. For example:
```
"abaca".strip("ac")
```
Produces:
```
'b'
```
since all instances of `"a"` an... |
64,211,267 | I want to install package MetaTrader5 on my Linux [Fedora], but this package is supported only for Windows.
**And my question is:** Is it possible to install Windows Python packages on Linux? and after installation import in my python file?
**My Solution**
1. install `wine` (learn more about [wine](https://www.wi... | 2020/10/05 | [
"https://Stackoverflow.com/questions/64211267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13033299/"
] | you can install `wine` to deal with the windows installer files in your fedora.
as per the doc, you can run the following comands one by one to install wine:
`sudo dnf clean all && sudo dnf update`
`dnf config-manager --add-repo https://dl.winehq.org/wine-builds/fedora/32/winehq.repo`
`sudo dnf install winehq-stabl... | Yes it possible to use Wine.
Its simply to do with **CrossOver**, its more stable.
Meta Trader compiled for the Wine.
Ive use this thing. Work correctly Meta Trader and Meta editor. |
41,883,254 | I am trying to process a form in django/python using the following code.
---
home.html:
```html
<form action="{% url 'home:submit' %}" method='post'>
```
---
views.py:
```py
def submit(request):
a = request.POST(['initial'])
return render(request, 'home/home.html', {
'error_message': "returned"
... | 2017/01/26 | [
"https://Stackoverflow.com/questions/41883254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7169431/"
] | In your main project, open url.py first. Then check, there should be app\_name declared at first. If it is not, declare it.
For example, my app name is user info which is declared in url.py
```
app_name = "userinfo"
urlpatterns = [
url(r'home/', views.home, name='home'),
url(r'register/', views.registration,... | Maybe someone will find this suggestion helpful.
Go to your applications `urls.py` and type this before the urlpatterns:
```
app_name = 'Your app name'
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.