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 |
|---|---|---|---|---|---|
3,856,314 | After using C# for long time I finally decided to switch to Python.
The question I am facing for the moment has to do about auto-complete.
I guess I am spoiled by C# and especially from resharper and I was expecting something similar to exist for Python.
My editor of choice is emacs and after doing some research I fou... | 2010/10/04 | [
"https://Stackoverflow.com/questions/3856314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404984/"
] | I find that [PyDev](http://pydev.org/) + Eclipse can meet most of my needs. There is also [PyCharm](http://www.jetbrains.com/pycharm/) from the Intellij team. PyCharm has the added advantage of smooth integration with git. | Take a look at [Spyderlib](http://code.google.com/p/spyderlib/), support most of the features including code completion |
3,856,314 | After using C# for long time I finally decided to switch to Python.
The question I am facing for the moment has to do about auto-complete.
I guess I am spoiled by C# and especially from resharper and I was expecting something similar to exist for Python.
My editor of choice is emacs and after doing some research I fou... | 2010/10/04 | [
"https://Stackoverflow.com/questions/3856314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404984/"
] | I found this post
>
> [My Emacs Python environment](http://www.saltycrane.com/blog/2010/05/my-emacs-python-environment/)
>
>
>
to be the most useful and comprehensive list of instructions and references on how to setup a decent Python development environment in Emacs regardless of OS platform. It is still a bit ... | Take a look at [Spyderlib](http://code.google.com/p/spyderlib/), support most of the features including code completion |
3,856,314 | After using C# for long time I finally decided to switch to Python.
The question I am facing for the moment has to do about auto-complete.
I guess I am spoiled by C# and especially from resharper and I was expecting something similar to exist for Python.
My editor of choice is emacs and after doing some research I fou... | 2010/10/04 | [
"https://Stackoverflow.com/questions/3856314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404984/"
] | I'm spoiled by Intellisense too. The PyDev extensions for Eclipse offer a pretty good auto-complete substitute. | I've been using [PyScripter](http://code.google.com/p/pyscripter), an IDE for Windows, for a while now, and have found it very good. It has autocompletion among many other features. It's written in Delphi -- not that there's anything wrong with that -- it just bothers me a bit, though... |
3,856,314 | After using C# for long time I finally decided to switch to Python.
The question I am facing for the moment has to do about auto-complete.
I guess I am spoiled by C# and especially from resharper and I was expecting something similar to exist for Python.
My editor of choice is emacs and after doing some research I fou... | 2010/10/04 | [
"https://Stackoverflow.com/questions/3856314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404984/"
] | I found this post
>
> [My Emacs Python environment](http://www.saltycrane.com/blog/2010/05/my-emacs-python-environment/)
>
>
>
to be the most useful and comprehensive list of instructions and references on how to setup a decent Python development environment in Emacs regardless of OS platform. It is still a bit ... | I'm spoiled by Intellisense too. The PyDev extensions for Eclipse offer a pretty good auto-complete substitute. |
3,856,314 | After using C# for long time I finally decided to switch to Python.
The question I am facing for the moment has to do about auto-complete.
I guess I am spoiled by C# and especially from resharper and I was expecting something similar to exist for Python.
My editor of choice is emacs and after doing some research I fou... | 2010/10/04 | [
"https://Stackoverflow.com/questions/3856314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404984/"
] | I found this post
>
> [My Emacs Python environment](http://www.saltycrane.com/blog/2010/05/my-emacs-python-environment/)
>
>
>
to be the most useful and comprehensive list of instructions and references on how to setup a decent Python development environment in Emacs regardless of OS platform. It is still a bit ... | IMO, by far the easiest way to take advantage of the python tools available for emacs is to take advantage of the defaults that are all set up at:
<https://github.com/gabrielelanaro/emacs-for-python>
I actually took the time to get pymacs and ropemacs and python-mode all working independently before finding that littl... |
3,856,314 | After using C# for long time I finally decided to switch to Python.
The question I am facing for the moment has to do about auto-complete.
I guess I am spoiled by C# and especially from resharper and I was expecting something similar to exist for Python.
My editor of choice is emacs and after doing some research I fou... | 2010/10/04 | [
"https://Stackoverflow.com/questions/3856314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404984/"
] | I find that [PyDev](http://pydev.org/) + Eclipse can meet most of my needs. There is also [PyCharm](http://www.jetbrains.com/pycharm/) from the Intellij team. PyCharm has the added advantage of smooth integration with git. | I've been using [PyScripter](http://code.google.com/p/pyscripter), an IDE for Windows, for a while now, and have found it very good. It has autocompletion among many other features. It's written in Delphi -- not that there's anything wrong with that -- it just bothers me a bit, though... |
3,856,314 | After using C# for long time I finally decided to switch to Python.
The question I am facing for the moment has to do about auto-complete.
I guess I am spoiled by C# and especially from resharper and I was expecting something similar to exist for Python.
My editor of choice is emacs and after doing some research I fou... | 2010/10/04 | [
"https://Stackoverflow.com/questions/3856314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404984/"
] | I'm spoiled by Intellisense too. The PyDev extensions for Eclipse offer a pretty good auto-complete substitute. | IMO, by far the easiest way to take advantage of the python tools available for emacs is to take advantage of the defaults that are all set up at:
<https://github.com/gabrielelanaro/emacs-for-python>
I actually took the time to get pymacs and ropemacs and python-mode all working independently before finding that littl... |
3,856,314 | After using C# for long time I finally decided to switch to Python.
The question I am facing for the moment has to do about auto-complete.
I guess I am spoiled by C# and especially from resharper and I was expecting something similar to exist for Python.
My editor of choice is emacs and after doing some research I fou... | 2010/10/04 | [
"https://Stackoverflow.com/questions/3856314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404984/"
] | I found this post
>
> [My Emacs Python environment](http://www.saltycrane.com/blog/2010/05/my-emacs-python-environment/)
>
>
>
to be the most useful and comprehensive list of instructions and references on how to setup a decent Python development environment in Emacs regardless of OS platform. It is still a bit ... | I've been using [PyScripter](http://code.google.com/p/pyscripter), an IDE for Windows, for a while now, and have found it very good. It has autocompletion among many other features. It's written in Delphi -- not that there's anything wrong with that -- it just bothers me a bit, though... |
55,062,944 | I have seen multiple posts on passing the string but not able to find good solution on reading the string passed to python script from batch file. Here is my problem.
I am calling python script from batch file and passing the argument.
```
string_var = "123_Asdf"
bat 'testscript.py %string_var%'
```
I have follow... | 2019/03/08 | [
"https://Stackoverflow.com/questions/55062944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7442477/"
] | You can order by a field created with annotate:
```
from django.db.models import IntegerField, Value as V
from django.db.models.functions import Cast, StrIndex, Substr
last = (
Machine.objects.annotate(
part=Cast(Substr("deviceSerialNo", StrIndex("deviceSerialNo", V("-"))), IntegerField())
)
.orde... | If number have multiple - and want to extract out number from reverse then try following. AB-12-12344
Output: 12344
```
qs.annotate(
r_part=Reverse('number')
).annotate(
part=Reverse(
Cast(
Substr("r_part", 1, StrIndex("r_part", V("-")))
),
IntegerField()
)
```
)
tha... |
55,062,944 | I have seen multiple posts on passing the string but not able to find good solution on reading the string passed to python script from batch file. Here is my problem.
I am calling python script from batch file and passing the argument.
```
string_var = "123_Asdf"
bat 'testscript.py %string_var%'
```
I have follow... | 2019/03/08 | [
"https://Stackoverflow.com/questions/55062944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7442477/"
] | You can order by a field created with annotate:
```
from django.db.models import IntegerField, Value as V
from django.db.models.functions import Cast, StrIndex, Substr
last = (
Machine.objects.annotate(
part=Cast(Substr("deviceSerialNo", StrIndex("deviceSerialNo", V("-"))), IntegerField())
)
.orde... | You can sort the objects using the extra() function:
```
your_objects = Machine.objects.all()
your_objects = your_objects.extra(select={'str_deviceSerialNo':'SUBSTRING("deviceSerialNo",initial_char,last_char)'}).order_by('str_deviceSerialNo')
```
It worked for me. |
18,401,287 | I am trying to build documentation for my flask project, and I am experiencing issues with the path
My project structure is like:
```
myproject
config
all.py
__init__.py
logger.py
logger.conf
myproject
models.py
__init__.py
en (english language docs folder)
... | 2013/08/23 | [
"https://Stackoverflow.com/questions/18401287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2080641/"
] | It is the behaviour of `open()` that is the problem. Commands like `open()` and `chdir()` and so work from the directory you're now in, which is probably the directory where the makefile is.
To test it, add an `print(os.listdir('.')` above your call to `open('logger.conf')`, that'll show you the problem.
The solution... | I had a similar problem when generating sphinx documentation for some python code that was not written to be run in my computer, but in an embedded system instead. In that case, the existing code attempted to open a file that did not exist in my computer, and that made sphinx fail. In this case, I decided to change the... |
54,681,449 | I upgraded from pandas 0.20.3 to pandas 0.24.1. While running the command `ts.sort_index(inplace=True)`, I am getting a `FutureWarning` in my test output, which is shown below. Can I change the method call to suppress the following warning? I am happy to keep the old behavior.
```
/lib/python3.6/site-packages/pandas/c... | 2019/02/14 | [
"https://Stackoverflow.com/questions/54681449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4808588/"
] | I rewrote your question [here](https://stackoverflow.com/questions/54854900/workaround-for-pandas-futurewarning-when-sorting-a-datetimeindex), to include an MCVE. After it went a while with no responses, I posted an issue against Pandas.
Here's my workaround:
```
with warnings.catch_warnings():
# Bug in Pandas em... | If I were you, I would do a downgrade using pip and setting the previous version. It's the lazier answer.
But if you really want to keep it upgraded, then there is a parameter call deprecated warning inside pandas data frame. Just adjust it accordingly what you need. You can check it using the documentation of pandas. ... |
29,585,296 | I have the following code (test.cgi):
```
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello World!"
```
The file is CHMOD 777 and so is the directory it is in.
I am getting the following error log
```
[S... | 2015/04/12 | [
"https://Stackoverflow.com/questions/29585296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1103669/"
] | Flatten the list by using `itertools.chain`, then find the minimum as you would otherwise:
```
from itertools import chain
listA = [[10,20,30],[40,50,60],[70,80,90]]
min(chain.from_iterable(listA))
# 10
``` | Set `result` to `float("inf")`. Iterate over every number in every list and call each number `i`. If `i` is less than `result`, `result = i`. Once you're done, `result` will contain the lowest value. |
29,585,296 | I have the following code (test.cgi):
```
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello World!"
```
The file is CHMOD 777 and so is the directory it is in.
I am getting the following error log
```
[S... | 2015/04/12 | [
"https://Stackoverflow.com/questions/29585296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1103669/"
] | ```
>>> listA = [[10,20,30],[40,50,60],[70,80,90]]
>>> min(y for x in listA for y in x)
10
``` | Set `result` to `float("inf")`. Iterate over every number in every list and call each number `i`. If `i` is less than `result`, `result = i`. Once you're done, `result` will contain the lowest value. |
29,585,296 | I have the following code (test.cgi):
```
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello World!"
```
The file is CHMOD 777 and so is the directory it is in.
I am getting the following error log
```
[S... | 2015/04/12 | [
"https://Stackoverflow.com/questions/29585296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1103669/"
] | Flatten the list by using `itertools.chain`, then find the minimum as you would otherwise:
```
from itertools import chain
listA = [[10,20,30],[40,50,60],[70,80,90]]
min(chain.from_iterable(listA))
# 10
``` | ```
>>> listA = [[10,20,30],[40,50,60],[70,80,90]]
>>> min(y for x in listA for y in x)
10
``` |
29,585,296 | I have the following code (test.cgi):
```
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello World!"
```
The file is CHMOD 777 and so is the directory it is in.
I am getting the following error log
```
[S... | 2015/04/12 | [
"https://Stackoverflow.com/questions/29585296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1103669/"
] | Flatten the list by using `itertools.chain`, then find the minimum as you would otherwise:
```
from itertools import chain
listA = [[10,20,30],[40,50,60],[70,80,90]]
min(chain.from_iterable(listA))
# 10
``` | This is possible using list comprehension
```
>>> listA = [[10,20,30],[40,50,60],[70,80,90]]
>>> output = [y for x in listA for y in x]
>>> min(output)
10
``` |
29,585,296 | I have the following code (test.cgi):
```
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello World!"
```
The file is CHMOD 777 and so is the directory it is in.
I am getting the following error log
```
[S... | 2015/04/12 | [
"https://Stackoverflow.com/questions/29585296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1103669/"
] | ```
>>> listA = [[10,20,30],[40,50,60],[70,80,90]]
>>> min(y for x in listA for y in x)
10
``` | This is possible using list comprehension
```
>>> listA = [[10,20,30],[40,50,60],[70,80,90]]
>>> output = [y for x in listA for y in x]
>>> min(output)
10
``` |
16,505,259 | I am new in django and python.I am using windows 7 and Eclipse IDE.I have installed python 2.7,django and pip.I have created a system variable called PYTHONPATH with values `C:\Python27;C:\Python27\Scripts`.I am unable to set path for django and pip.When i type django-admin.py and pip in powershell,it shows `commandnot... | 2013/05/12 | [
"https://Stackoverflow.com/questions/16505259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1770199/"
] | You need to set the Powershell specific path variable. It does not know to look for an environment variable called `pythonpath`. That is helpful only for python aware applications (such as installers for Python modules).
You need to add the Python directories to the `$env:Path` environment variable in Powershell. See... | Also, if you're just getting started with Django and Eclipse, make sure you configure your PyDev interpreter settings to include the site-packages directory. This will ensure Eclipse can find your Django packages.
You can find more details about setting up your PYTHONPATH inside Eclipse here:
[PyDev Interpreter Conf... |
2,767,013 | I think in the past python scripts would run off CGI, which would create a new thread for each process.
I am a newbie so I'm not really sure, what options do we have?
Is the web server pipeline that python works under any more/less effecient than say php? | 2010/05/04 | [
"https://Stackoverflow.com/questions/2767013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] | You can still use CGI if you want, but the normal approach these days is using WSGI on the Python side, e.g. through `mod_wsgi` on Apache or via bridges to `FastCGI` on other web servers. At least with `mod_wsgi`, I know of no inefficiencies with this approach.
BTW, your description of CGI ("create a new thread for ea... | I suggest cherrypy (<http://www.cherrypy.org/>). It is very convenient to use, has everything you need for making web services, but still quite simple (no mega-framework). The most efficient way to use it is to run it as self-contained server on localhost and put it behind Apache via a Proxy statement, and make apache ... |
2,767,013 | I think in the past python scripts would run off CGI, which would create a new thread for each process.
I am a newbie so I'm not really sure, what options do we have?
Is the web server pipeline that python works under any more/less effecient than say php? | 2010/05/04 | [
"https://Stackoverflow.com/questions/2767013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] | You can still use CGI if you want, but the normal approach these days is using WSGI on the Python side, e.g. through `mod_wsgi` on Apache or via bridges to `FastCGI` on other web servers. At least with `mod_wsgi`, I know of no inefficiencies with this approach.
BTW, your description of CGI ("create a new thread for ea... | I would suggest Django <http://www.djangoproject.com>. It is very convenient to use, has everything you need for making web services. The most efficient way to use it is to run it as via Apache's mod\_wsgi, and make Apache itself serve the static files.
This generally has better performance than solutions such as CGI ... |
2,767,013 | I think in the past python scripts would run off CGI, which would create a new thread for each process.
I am a newbie so I'm not really sure, what options do we have?
Is the web server pipeline that python works under any more/less effecient than say php? | 2010/05/04 | [
"https://Stackoverflow.com/questions/2767013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] | I would suggest Django <http://www.djangoproject.com>. It is very convenient to use, has everything you need for making web services. The most efficient way to use it is to run it as via Apache's mod\_wsgi, and make Apache itself serve the static files.
This generally has better performance than solutions such as CGI ... | I suggest cherrypy (<http://www.cherrypy.org/>). It is very convenient to use, has everything you need for making web services, but still quite simple (no mega-framework). The most efficient way to use it is to run it as self-contained server on localhost and put it behind Apache via a Proxy statement, and make apache ... |
21,102,790 | I am using RHEL 6.3 and have 2.6.6. I need to use the Python 2.7.6. I compiled python from source, installed pip and virtual env.
Now I am trying in different ways:
```
virtualenv-2.7 testvirtualenv
virtualenv --python=/usr/local/bin/python2.7 myenv
```
However I am getting AssertionError. Full trace:
```
New ... | 2014/01/13 | [
"https://Stackoverflow.com/questions/21102790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2195440/"
] | You need type composition:
```
trait Composition[F[_], G[_]] { type T[A] = F[G[A]] }
class Later extends Do[Composition[Future, Seq]#T] {
def do[A](f: Int => A): Future[Seq[A]]
}
```
Or if you just need it in this one place
```
class Later extends Do[({ type T[A] = Future[Seq[A]] })#T] {
def do[A](f: Int => A)... | **I** believe you want this:
```
import scala.language.higherKinds
import scala.concurrent.Future
object Main {
type Id[A] = A
trait Do[F[_]] {
// Notice the return type now contains `Seq`.
def `do`[A](f: Int => A): F[Seq[A]]
}
class Now extends Do[Id] {
override def `do`[A](f: Int => A): Seq[A]... |
21,102,790 | I am using RHEL 6.3 and have 2.6.6. I need to use the Python 2.7.6. I compiled python from source, installed pip and virtual env.
Now I am trying in different ways:
```
virtualenv-2.7 testvirtualenv
virtualenv --python=/usr/local/bin/python2.7 myenv
```
However I am getting AssertionError. Full trace:
```
New ... | 2014/01/13 | [
"https://Stackoverflow.com/questions/21102790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2195440/"
] | You need type composition:
```
trait Composition[F[_], G[_]] { type T[A] = F[G[A]] }
class Later extends Do[Composition[Future, Seq]#T] {
def do[A](f: Int => A): Future[Seq[A]]
}
```
Or if you just need it in this one place
```
class Later extends Do[({ type T[A] = Future[Seq[A]] })#T] {
def do[A](f: Int => A)... | Alexey's solution is very clever and answers the question you made. However, I think you made the from question.
You started with these two interfaces:
```
class Now {
def do[A](f: Int => A): Seq[A]
}
class Later {
def do[A](f: Int => A): Future[Seq[A]]
}
```
and want to modify `Later` so it implements this:
... |
20,986,255 | In our application we allow users to write specific conditions and we allow them express the conditions using such notation:
```
(1 and 2 and 3 or 4)
```
Where each numeric number correspond to one specific rule/condition. Now the problem is, how should I convert it, such that the end result is something like this:
... | 2014/01/08 | [
"https://Stackoverflow.com/questions/20986255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/534862/"
] | This is most easily done using a two step process.
1) Convert to syntax tree.
2) Convert syntax tree to prefix notation.
A syntax tree is basically the same as your prefix notation, just built using the data structures of your programming language.
The standard method to create a syntax tree is to use a LALR parser g... | First define semantics. In your first example you gave `(1 and 2 and 3) or 4` interpretation but it can also be `1 and 2 and (3 or 4)` so:
```
{
"$and": [
{"$or": [3,4] },
[1,2]
]
}
```
Let's assume that `and` has higher priority. Then just go through list join all terms with `and`. Next, joi... |
20,986,255 | In our application we allow users to write specific conditions and we allow them express the conditions using such notation:
```
(1 and 2 and 3 or 4)
```
Where each numeric number correspond to one specific rule/condition. Now the problem is, how should I convert it, such that the end result is something like this:
... | 2014/01/08 | [
"https://Stackoverflow.com/questions/20986255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/534862/"
] | Thanks for the guides guys, at least I came out with my own solution. Since this is my first time doing mathematical equation parsing, pardon me if I did it wrongly or inefficient, or help me spot the error:
Basically, here are the steps I made it happen:
1. Before parsing, always validate the pattern. Throw error wh... | This is most easily done using a two step process.
1) Convert to syntax tree.
2) Convert syntax tree to prefix notation.
A syntax tree is basically the same as your prefix notation, just built using the data structures of your programming language.
The standard method to create a syntax tree is to use a LALR parser g... |
20,986,255 | In our application we allow users to write specific conditions and we allow them express the conditions using such notation:
```
(1 and 2 and 3 or 4)
```
Where each numeric number correspond to one specific rule/condition. Now the problem is, how should I convert it, such that the end result is something like this:
... | 2014/01/08 | [
"https://Stackoverflow.com/questions/20986255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/534862/"
] | Thanks for the guides guys, at least I came out with my own solution. Since this is my first time doing mathematical equation parsing, pardon me if I did it wrongly or inefficient, or help me spot the error:
Basically, here are the steps I made it happen:
1. Before parsing, always validate the pattern. Throw error wh... | First define semantics. In your first example you gave `(1 and 2 and 3) or 4` interpretation but it can also be `1 and 2 and (3 or 4)` so:
```
{
"$and": [
{"$or": [3,4] },
[1,2]
]
}
```
Let's assume that `and` has higher priority. Then just go through list join all terms with `and`. Next, joi... |
43,005,480 | Let's say that I have three lists and want to add all elements that are integers to a list named `int_list`:
```
test1 = [1, 2, 3, "b", 6]
test2 = [1, "foo", "bar", 7]
test3 = ["more stuff", 1, 4, 99]
int_list = []
```
I know that I can do the following code to append all integers to a new list:
```
for elem1, ele... | 2017/03/24 | [
"https://Stackoverflow.com/questions/43005480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6779980/"
] | When you import the data into Excel, tell the **Import Wizard** that the field is *Text*.
[](https://i.stack.imgur.com/tqMFm.png) | My preference is to deal with the inputs, when possible, and in this case if you have control over the python script, it may be preferable to simply modify *that*, so that Excel's default behavior interprets the file in the desired way.
Borrowing from [this similar question with a million upvotes](https://stackoverflo... |
60,286,051 | I have a python script and want to call a subprocess from it.
The following example works completely fine:
Script1:
```
from subprocess import Popen
p = Popen('python Script2.py', shell=True)
```
Script2:
```
def execute():
print('works!')
execute()
```
However as soon as I want to pass a variable to the f... | 2020/02/18 | [
"https://Stackoverflow.com/questions/60286051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12920312/"
] | There is file called extensions.json in the bin folder. Your startup calls register in that file. Whichever function app deployed latest, that function's startup call will be replaced with earlier function's startup call. So, you need to take an action that all the functions' startup calls will be registered in this fi... | Seems like you haven't [injected](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.1) `IAzureTableStorageService` properly in your Startup class hence the DI can't find it. Reference the project where `IAzureTableStorageService` is located, add something like this in you... |
1,083,391 | Please, help me in: how to put a double command in the *cmd*, like this in the Linux: `apt-get install firefox && cp test.py /home/python/`, but how to do this in Windows?, more specific in Windows CE, but it´s the same in Windows and in Windows CE, because the *cmd* is the same. Thanks! | 2009/07/05 | [
"https://Stackoverflow.com/questions/1083391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126353/"
] | If CE is the same as XP Pro (and I'm not sure you're right about that), you can use the same method:
```
dir && echo hello
```
Here it is running on my Windows VM (XP SP3):
```
C:\Documents and Settings\Pax>dir && echo hello
Volume in drive C is Primary
Volume Serial Number is 04F7-0E7B
Directory of C:\Document... | This <http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true> might be of some help.
cheers |
17,620,875 | I'm python developer and most frequently I use [buildout](http://www.buildout.org/en/latest/) for managing my projects. In this case I dont ever need to run any command to activate my dependencies environment.
However, sometime I use virtualenv when buildout is to complicated for this particular case.
Recently I st... | 2013/07/12 | [
"https://Stackoverflow.com/questions/17620875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/375373/"
] | One feature of Unix shells is that they let you create *shell functions*, which are much like functions in other languages; they are essentially named groups of commands. For example, you can write a function named `mycd` that first runs `cd`, and then runs other commands:
```
function mycd () {
cd "$@"
if ...... | I think you're looking for one of two things.
[`autoenv`](https://github.com/kennethreitz/autoenv) is a relatively simple tool that creates the relevant bash functions for you. It's essentially doing what ruakh suggested, but you can use it without having to know how the shell works.
[`virtualenvwrapper`](https://pyp... |
17,620,875 | I'm python developer and most frequently I use [buildout](http://www.buildout.org/en/latest/) for managing my projects. In this case I dont ever need to run any command to activate my dependencies environment.
However, sometime I use virtualenv when buildout is to complicated for this particular case.
Recently I st... | 2013/07/12 | [
"https://Stackoverflow.com/questions/17620875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/375373/"
] | One feature of Unix shells is that they let you create *shell functions*, which are much like functions in other languages; they are essentially named groups of commands. For example, you can write a function named `mycd` that first runs `cd`, and then runs other commands:
```
function mycd () {
cd "$@"
if ...... | Just found in the description of virtualenvwraper [this topic](http://virtualenvwrapper.readthedocs.org/en/latest/tips.html#changing-the-default-behavior-of-cd)
It describes exactly what I need. |
17,620,875 | I'm python developer and most frequently I use [buildout](http://www.buildout.org/en/latest/) for managing my projects. In this case I dont ever need to run any command to activate my dependencies environment.
However, sometime I use virtualenv when buildout is to complicated for this particular case.
Recently I st... | 2013/07/12 | [
"https://Stackoverflow.com/questions/17620875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/375373/"
] | I think you're looking for one of two things.
[`autoenv`](https://github.com/kennethreitz/autoenv) is a relatively simple tool that creates the relevant bash functions for you. It's essentially doing what ruakh suggested, but you can use it without having to know how the shell works.
[`virtualenvwrapper`](https://pyp... | Just found in the description of virtualenvwraper [this topic](http://virtualenvwrapper.readthedocs.org/en/latest/tips.html#changing-the-default-behavior-of-cd)
It describes exactly what I need. |
62,389,496 | I wanted to write a Python Script that lists all files in the current working directory, if the **length** of a file's name is between 3 - 6 characters long. Also, it should only list files with the extension `.py`
I was not able to find any specific function that would return the legnth of a files name, only the siz... | 2020/06/15 | [
"https://Stackoverflow.com/questions/62389496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12781947/"
] | Maybe rewording `file` to `filename` might make things clearer...
```
import os
for filename in os.listdir(os.getcwd()):
if filename.endswith(".py"):
print(filename, len(filename))
```
Now since you know how `if` statements work, you can probably do something with `len(filename)`? :) | your variable `file` is a string
so, you can use a function for retrive a lenght of a string
```
for file in os.listdir(os.getcwd()):
if file.endswith(".py"):
print(file, len(file))
``` |
62,389,496 | I wanted to write a Python Script that lists all files in the current working directory, if the **length** of a file's name is between 3 - 6 characters long. Also, it should only list files with the extension `.py`
I was not able to find any specific function that would return the legnth of a files name, only the siz... | 2020/06/15 | [
"https://Stackoverflow.com/questions/62389496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12781947/"
] | You can try
```
import os
for file in os.listdir(os.getcwd()):
if file.endswith(".py") and 3 <= len(file[:file.find(".")]) <= 6:
print(file)
```
This will print only files that have between 3 and 6 chars in the filename without the file extension. | your variable `file` is a string
so, you can use a function for retrive a lenght of a string
```
for file in os.listdir(os.getcwd()):
if file.endswith(".py"):
print(file, len(file))
``` |
21,957,231 | I'm very new to d3 and in order to learn I'm trying to manipulate the [d3.js line example](http://bl.ocks.org/mbostock/3883245), the code is below. I'm trying to modify this to use model data that I already have on hand. This data is passed down as a json object. The problem is that I don't know how to manipulate the d... | 2014/02/22 | [
"https://Stackoverflow.com/questions/21957231",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1870013/"
] | ```
for (String hashTagged : hashTags) {
if (tweet.equalsIgnoreCase(hashTagged) != true) {
hashTags.add(hashTagged);
-----------------------------^
}
}
```
The issue is while iterating the hashTags list you cant upda... | You are getting `java.util.ConcurrentModificationException` because you are modifying the `List` `hashTags` while you are iterating over it.
```
for (String hashTagged : hashTags) {
if (tweet.equalsIgnoreCase(hashTagged) != true) {
hashTags.add(hashTagged);
}
}
```
You can create a temporary list of ... |
65,736,625 | In python, I have a datetime object in python with that format.
```
datetime_object = datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S')
```
In other classes, I'm using this object. When i reach this object,i want to extract time from it and compare string time.
Like below;
```
if "01:15:13" == time_from_dateti... | 2021/01/15 | [
"https://Stackoverflow.com/questions/65736625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14697436/"
] | You need to use the strftime method:
```
from datetime import datetime
date_time_str = '2021-01-15 01:15:13'
datetime_object = datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S')
if "01:15:13" == datetime_object.strftime('%H:%M:%S'):
print("match")
``` | If you want to compare it as string:
```
if "01:15:13" == datetime_object.strftime('%H:%M:%S'):
``` |
65,736,625 | In python, I have a datetime object in python with that format.
```
datetime_object = datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S')
```
In other classes, I'm using this object. When i reach this object,i want to extract time from it and compare string time.
Like below;
```
if "01:15:13" == time_from_dateti... | 2021/01/15 | [
"https://Stackoverflow.com/questions/65736625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14697436/"
] | You need to use the strftime method:
```
from datetime import datetime
date_time_str = '2021-01-15 01:15:13'
datetime_object = datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S')
if "01:15:13" == datetime_object.strftime('%H:%M:%S'):
print("match")
``` | Use its [`time`](https://docs.python.org/3/library/datetime.html?highlight=datetime.datetime.time#datetime.datetime.time) method to return a `time` object, which you can compare to another `time` object.
```
from datetime import time
if datetime_object.time() == time(1, 15, 13):
...
```
You may have to be caref... |
7,172,585 | >
> **Possible Duplicate:**
>
> [Should Python import statements always be at the top of a module?](https://stackoverflow.com/questions/128478/should-python-import-statements-always-be-at-the-top-of-a-module)
>
>
>
In a very simple one-file python program like
```
# ------------------------
# place 1
# impor... | 2011/08/24 | [
"https://Stackoverflow.com/questions/7172585",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/909210/"
] | [PEP 8](http://www.python.org/dev/peps/pep-0008/) specifies that:
* Imports are always put at the top of the file, just after any module
comments and docstrings, and before module globals and constants.
Imports should be grouped in the following order:
1. standard library imports
2. related third party imports
3... | I'd principally agree with Robert S. answer, but sometimes it makes sense to put it into a function. Especially if you want to control the importing mechanism. This is useful if you cannot be sure if you actually have access to a specific module. Consider this example:
```
def foo():
try:
import somespecia... |
19,328,381 | I am confused about classes in python. I don't want anyone to write down raw code but suggest methods of doing it. Right now I have the following code...
```
def main():
lst = []
filename = 'yob' + input('Enter year: ') + '.txt'
for line in open(filename):
line = line.strip()
lst.append(lin... | 2013/10/11 | [
"https://Stackoverflow.com/questions/19328381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2835743/"
] | You can use reflection
```
item.GetType().GetProperty(field).GetValue(item).ToString();
```
(or `GetField()` instead of `GetProperty()` if... that's a field) | This is not trivial like it might be, say, in ecmascript. The simplest option is reflection, for example:
```
data = item.GetType().GetProperty(field).GetValue(item).ToString();
```
however: depending on the API involved, there may be other options available involving indexers, etc. Note that reflection is slower th... |
53,327,826 | Many open-source projects use a "Fork me on Github" banner at the top-right corner of the pages in the documentation.
To name just one, let's take the example of Python [requests](http://docs.python-requests.org/en/master/):
[](https://i.stack.imgur.com/... | 2018/11/15 | [
"https://Stackoverflow.com/questions/53327826",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2291710/"
] | The easiest way is to use an alternative theme like [`alabaster`](https://pypi.org/project/alabaster/) as it comes with preconfigured option like `github_banner` (see [Joran's answer](https://stackoverflow.com/a/53328720/2291710)).
For other themes like `sphinx-rtd-theme` which do not provide such setting, the solutio... | the great thing about python (especially python on github) is that you can simply look at the source
I can go to <https://github.com/requests/requests/blob/master/docs/conf.py> and look at their conf.py
where we can see this entry
```
# Theme options are theme-specific and customize the look and feel of a theme
# f... |
44,922,108 | The objective is to parse the output of an ill-behaving program which concatenates a list of numbers, e.g., 3, 4, 5, into a string "345", without any non-number separating the numbers. I also know that the list is sorted in ascending order.
I came up with the following solution which reconstructs the list from a strin... | 2017/07/05 | [
"https://Stackoverflow.com/questions/44922108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2618889/"
] | This finds solutions for all possible initial number lengths:
```
a = '3456781015203040'
def numbers(a,n):
current_num, i = 0, 0
while True:
while i+n <= len(a) and int(a[i:i+n]) <= current_num:
n += 1
if i+n <= len(a):
current_num = int(a[i:i+n])
yield curr... | little modification which allows to parse "7000000000001" data and give the best output (max list size)
```
a = 30000001
def numbers(a,n):
current_num, i = 0, 0
while True:
while i+n <= len(a) and int(a[i:i+n]) <= current_num:n += 1
if i+2*n>len(a):current_num = int(a[i:]);yield current_num; re... |
64,765,086 | im trying to run a server on my laptop, when in the console i type 'python manage.py runserver'
i recieve some errors. could it be i need to import some modules i tried 'pip install python-cron' but that didnt work.
the error says:
```
[2020-11-10 09:04:47,241] autoreload: INFO - Watching for file changes with StatRel... | 2020/11/10 | [
"https://Stackoverflow.com/questions/64765086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13740000/"
] | I have tried to re-create the same design with some minor changes in Flutter. I have to enable flutter web support by following the instructions here:
[Flutter Web](https://flutter.dev/docs/get-started/web)
[](https://i.stack.imgur.com/oxX5K.gif)
Regarding the... | You can use the `Drawer` widget inside a `Scaffold`. If you want the navigation drawer to be able to resize according to the browser height and width you can use the [responsive\_scaffold](https://pub.dev/packages/responsive_scaffold) package. |
22,073,028 | I just started python three days ago and I am already facing a problem. I couldn't get any information in the www. It looks like a bug - but I think I did s.th. wrong.
However I can't find the problem.
Here we go:
I have 1 List called "inputData".
So all I do is, take out the first 10 entries in each array, fit it w... | 2014/02/27 | [
"https://Stackoverflow.com/questions/22073028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3361064/"
] | Your `inputData` isn't a numpy array, it's a list of arrays. Those two lists don't have the same length:
```
>>> [len(sl) for sl in inputData]
[11, 10]
```
numpy arrays can't handle varying lengths. If you try to make an array out of it, instead of having a 2-D array of float dtype, you get a 1-D array of object dty... | Your code as you posted it is not runnable at all, as a bunch of definitions are missing or wrong. After fixing this and some code cleanup, I get the following, which basically shows, everything is working as intended:
```
import numpy as np
from copy import deepcopy
dataList = [np.array([[ 1.06999998e+01, 1.71811... |
73,749,184 | I'm following this [TensorFlow guide](https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10) for object detection models and I've gotten to part 6, which is training your program. I've input this line of code,
```
python train.py --logtostderr --train_dir=trainin... | 2022/09/16 | [
"https://Stackoverflow.com/questions/73749184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19228228/"
] | I wold try something like this
```
var paymentStatus = JObject.Parse(response.Content)["PaymentStatus"][0];
string statusDescription = paymentStatus["StatusDescription"].ToString();
string merchantTxnRefNo = paymentStatus["MerchantTxnRefNo"].ToString();
```
or maybe you need c# classes
```
List<PaymentStatus> pay... | Since PaymentStatus resolves to an array, use the indexer to get the object as below
var StatusDescription = (string)jObject["PaymentStatus"]`[0]`["MerchantTxnRefNo"]; |
52,747,655 | I am trying to use the TensorFlow CLI debugger in order to identify the operation which is causing a NaN during training of a network, but when I try to run the code I get an error:
`_curses.error: cbreak() returned ERR`
I'm running the code on an Ubuntu server, which I'm connecting to via SSH, and have tried to foll... | 2018/10/10 | [
"https://Stackoverflow.com/questions/52747655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9067015/"
] | Problem solved! The solution was to change
```
sess = tf_debug.LocalCLIDebugWrapperSession(sess)
```
to
```
sess = tf_debug.LocalCLIDebugWrapperSession(sess, ui_type="readline")
```
This is similar to the solution to [this question](https://stackoverflow.com/questions/47833697/how-to-use-tensorflow-debugging-tool... | `cbreak` would return **`ERR`** if you run a curses application that is not on a *real terminal* (i.e., something that works with [POSIX termios calls](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11)).
From the description,
>
> but the layers in the network include while loops so are ... |
12,397,182 | I am trying to remove all the html surrounding the data that I seek from a webpage so that all that is left is the raw data that I will then be able to input into a database. so if I have something like:
```
<p class="location"> Atlanta, GA </p>
```
The following code would return
```
Atlanta, GA </p>
```
But wha... | 2012/09/12 | [
"https://Stackoverflow.com/questions/12397182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/845888/"
] | As rightfully pointed out in the comments, you should be using a specific library to parse HTML and extract text, here are some examples:
* [html2text](http://www.aaronsw.com/2002/html2text/): Limited functionnality, but exactly what you need.
* [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/): More comp... | Assuming all you want is to extract the data contained in `<p class="location">` tags, you could use a quick & dirty (but correct) approach with the Python `HTMLParser` module (a simple HTML SAX parser), like this:
```
from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
PLocationID=0
PCount=0
... |
64,777,843 | Today I come with a two in one set of issues that's on the verge of making me smash my computer to pieces! So please I would greatly appreciate any help as I've been stuck on it for two days now.
I have a project where osmnx is required, so I follow the install instructions [provided](https://github.com/gboeing/osmnx#... | 2020/11/10 | [
"https://Stackoverflow.com/questions/64777843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9935756/"
] | Following droptop recommendation, I actually just did a full clean (another one) reinstall of anaconda where I deleted almost everything that I could.
I installed it again and it's working now! Thanks for the help anyway!! | Your fresh anaconda install should have `jupyter`, `jupyterlab` and `spyder` in the `base` environment. Starting the anaconda prompt and typing in `jupyter notebook` should launch jupyter.
Try activating your `ox2` environment with another prompt, and follow through from step 3 of this post <https://medium.com/@nrk256... |
59,519,338 | Error occurs upon `import numpy as np`; command works fine when typed directly in terminal, but fails when ran via [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner). My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | Based on your comment, it looks like the conda environment is not being activated by VSCode. Selecting the Python interpreter points VSCode to the Python executable (python.exe), but sometimes environmental variables that are set by Conda are used to tell packages with large backends where to look for the compiled bina... | If you deactivate the Code Runner extension and make sure you select the appropriate conda environment using the [Python extension for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python) you will get a green play button instead of a white one. That green play button will use the environment y... |
59,519,338 | Error occurs upon `import numpy as np`; command works fine when typed directly in terminal, but fails when ran via [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner). My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | Based on your comment, it looks like the conda environment is not being activated by VSCode. Selecting the Python interpreter points VSCode to the Python executable (python.exe), but sometimes environmental variables that are set by Conda are used to tell packages with large backends where to look for the compiled bina... | I had the same problem. In my case Anaconda3 and VS Code were installed separately. Here are the steps that worked for me to fix the problem:
* Completely uninstall VS Code including any user settings/cache and start menu entries
* Re-install VS Code from Anaconda Navigator
* Launch Anaconda Prompt and activate whiche... |
59,519,338 | Error occurs upon `import numpy as np`; command works fine when typed directly in terminal, but fails when ran via [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner). My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | Based on your comment, it looks like the conda environment is not being activated by VSCode. Selecting the Python interpreter points VSCode to the Python executable (python.exe), but sometimes environmental variables that are set by Conda are used to tell packages with large backends where to look for the compiled bina... | I had the same issue, I've fixed it by adding the `Python.CondaPath` in settings. Press `Ctrl + Shift + P` and select Terminal Configuration. Search for `python.conda`, and paste your conda path for example. C:\ProgramData\Anaconda3\Scripts\conda.exe
This will fix your issue.
[. My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | Based on your comment, it looks like the conda environment is not being activated by VSCode. Selecting the Python interpreter points VSCode to the Python executable (python.exe), but sometimes environmental variables that are set by Conda are used to tell packages with large backends where to look for the compiled bina... | The answer above are being depreciated by VS Code. The more modern solution is to force VS to activate the Anaconda when running Code standalone by adding:
```
"python.condaPath": "C:\\ProgramData\\Anaconda3\\Scripts\\conda.exe",
"python.terminal.activateEnvironment": true,
"terminal.integrated.defaultProfile.windows"... |
59,519,338 | Error occurs upon `import numpy as np`; command works fine when typed directly in terminal, but fails when ran via [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner). My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | I had the same problem. In my case Anaconda3 and VS Code were installed separately. Here are the steps that worked for me to fix the problem:
* Completely uninstall VS Code including any user settings/cache and start menu entries
* Re-install VS Code from Anaconda Navigator
* Launch Anaconda Prompt and activate whiche... | If you deactivate the Code Runner extension and make sure you select the appropriate conda environment using the [Python extension for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python) you will get a green play button instead of a white one. That green play button will use the environment y... |
59,519,338 | Error occurs upon `import numpy as np`; command works fine when typed directly in terminal, but fails when ran via [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner). My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | I had the same issue, I've fixed it by adding the `Python.CondaPath` in settings. Press `Ctrl + Shift + P` and select Terminal Configuration. Search for `python.conda`, and paste your conda path for example. C:\ProgramData\Anaconda3\Scripts\conda.exe
This will fix your issue.
[ you will get a green play button instead of a white one. That green play button will use the environment y... |
59,519,338 | Error occurs upon `import numpy as np`; command works fine when typed directly in terminal, but fails when ran via [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner). My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | The answer above are being depreciated by VS Code. The more modern solution is to force VS to activate the Anaconda when running Code standalone by adding:
```
"python.condaPath": "C:\\ProgramData\\Anaconda3\\Scripts\\conda.exe",
"python.terminal.activateEnvironment": true,
"terminal.integrated.defaultProfile.windows"... | If you deactivate the Code Runner extension and make sure you select the appropriate conda environment using the [Python extension for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python) you will get a green play button instead of a white one. That green play button will use the environment y... |
59,519,338 | Error occurs upon `import numpy as np`; command works fine when typed directly in terminal, but fails when ran via [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner). My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | I had the same problem. In my case Anaconda3 and VS Code were installed separately. Here are the steps that worked for me to fix the problem:
* Completely uninstall VS Code including any user settings/cache and start menu entries
* Re-install VS Code from Anaconda Navigator
* Launch Anaconda Prompt and activate whiche... | I had the same issue, I've fixed it by adding the `Python.CondaPath` in settings. Press `Ctrl + Shift + P` and select Terminal Configuration. Search for `python.conda`, and paste your conda path for example. C:\ProgramData\Anaconda3\Scripts\conda.exe
This will fix your issue.
[. My steps to reproduce below.
Output of `import sys; print(sys.version)` is `3.7.5 (default, Oct 31 2019, 15:18... | 2019/12/29 | [
"https://Stackoverflow.com/questions/59519338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10133797/"
] | The answer above are being depreciated by VS Code. The more modern solution is to force VS to activate the Anaconda when running Code standalone by adding:
```
"python.condaPath": "C:\\ProgramData\\Anaconda3\\Scripts\\conda.exe",
"python.terminal.activateEnvironment": true,
"terminal.integrated.defaultProfile.windows"... | I had the same issue, I've fixed it by adding the `Python.CondaPath` in settings. Press `Ctrl + Shift + P` and select Terminal Configuration. Search for `python.conda`, and paste your conda path for example. C:\ProgramData\Anaconda3\Scripts\conda.exe
This will fix your issue.
[ and use `submit` rather than `map`:
```
(pattern, executor.submit(processPattern, pattern, ...) for pattern in patterns)
```
To ensure that everything gets executed on the pool (instead of immediately), do not invoke t... | Python *for*-loop is has functional behavior, and it is not possible to change value, which is iterating.
```
with concurrent.futures.ProcessPoolExecutor() as executor:
def work(pattern):
return processPattern(pattern, numMismatchesAllowed, transformedText, charToIndex, countMatrix, firstOccurrence, suffi... |
21,870,728 | Hi I am trying to run the multiprocessing example in the docs: <http://docs.python.org/3.4/library/concurrent.futures.html>, the one using prime numbers but with a small difference.
I want to be able to call a function with multiple arguments. What I am doing is matching small pieces of text (in a list around 30k long... | 2014/02/19 | [
"https://Stackoverflow.com/questions/21870728",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3015449/"
] | Other posters have covered possible solutions, but to explain your error, you should be passing the function and parameters as separate objects to `executor.map`. Here is the example from the docs
```
with concurrent.futures.ProcessPoolExecutor() as executor:
# is_prime is the function, PRIMES are the arguments
... | Python *for*-loop is has functional behavior, and it is not possible to change value, which is iterating.
```
with concurrent.futures.ProcessPoolExecutor() as executor:
def work(pattern):
return processPattern(pattern, numMismatchesAllowed, transformedText, charToIndex, countMatrix, firstOccurrence, suffi... |
21,870,728 | Hi I am trying to run the multiprocessing example in the docs: <http://docs.python.org/3.4/library/concurrent.futures.html>, the one using prime numbers but with a small difference.
I want to be able to call a function with multiple arguments. What I am doing is matching small pieces of text (in a list around 30k long... | 2014/02/19 | [
"https://Stackoverflow.com/questions/21870728",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3015449/"
] | To get the data into the right shape, simply use a generator expression (no need for `zip` at all) and use `submit` rather than `map`:
```
(pattern, executor.submit(processPattern, pattern, ...) for pattern in patterns)
```
To ensure that everything gets executed on the pool (instead of immediately), do not invoke t... | Other posters have covered possible solutions, but to explain your error, you should be passing the function and parameters as separate objects to `executor.map`. Here is the example from the docs
```
with concurrent.futures.ProcessPoolExecutor() as executor:
# is_prime is the function, PRIMES are the arguments
... |
57,354,747 | I am trying to add a package to PyPi so I can install it with Pip. I am trying to add it using `twine upload dist/*`.
This causes me to get multiple SSL errors such as `raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='upload.pypi.org', port=443): Max retries exceeded with url... | 2019/08/05 | [
"https://Stackoverflow.com/questions/57354747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9868018/"
] | My guess is your school has something in place where they are replacing the original cert with their own, you could maybe get around it using `--cert` and referencing the path for your schools cert, but I think an easier workaround is to copy the files to a non school computer and upload from there. | This could be a number of things, including an out-of-date version of `twine`, or (more likely) an out-of-date version of OpenSSL. Some possible solutions are listed here: <https://github.com/pypa/twine/issues/273> |
48,313,388 | I am trying to get selenium working on my headless raspberry pi with firefox. I have it working fine on Windows with chrome. Here are my versions:
```
uname -a Linux megabyte.thompco.com 4.9.59-v7+ #1047 SMP Sun Oct 29
12:19:23 GMT 2017 armv7l GNU/Linux
which firefox
/usr/bin/firefox
firefox --version
Mozilla Firefo... | 2018/01/18 | [
"https://Stackoverflow.com/questions/48313388",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1039860/"
] | Finally got this to work, but with chromedriver and chrome.
You will have to install chrome first:
```
sudo apt-get install chromium-browser
```
Next downloaded the debian package from here:
<https://packages.debian.org/stretch/armhf/chromium-driver/download>
Unpack the file "chromedriver":
```
mkdir tmp
dpkg-deb -... | You can also try declaring the DISPLAY variable, it works especially for remote connections.
Run this command on the terminal:
```
export DISPLAY=:0.0
``` |
36,426,547 | I am using Ubuntu 14.04
I wanted to install package "requests" to use in python 3.5, so I installed it using pip3. I could see it in /usr/lib/python3.4, but while trying to actually execute scripts with Python 3.5 I always got "ImportError: No module named 'requests'"
OK, so I figured, perhaps that's because the pack... | 2016/04/05 | [
"https://Stackoverflow.com/questions/36426547",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4680896/"
] | **First of all, it is a very bad idea to remove your *system* Python 3 in Ubuntu (which 3.4 is in recent
subrevisions of Trusty LTS)**. That is because it is a **vital part of the system**. If you run the command `apt-cache rdepends python3`, you'd see that packages such as `ubuntu-minimal`, `ubuntu-release-upgrader-co... | Ubuntu 14.04LTS uses the [*trusty* package list](http://packages.ubuntu.com/trusty/). That repository comes with [Python 3.4.0-0ubuntu2](http://packages.ubuntu.com/trusty/python3). So the `pip` contained in `python3-pip` belongs to *that* version: 3.4.
As such, when using Python 3.5, packages installed using Python 3.... |
36,426,547 | I am using Ubuntu 14.04
I wanted to install package "requests" to use in python 3.5, so I installed it using pip3. I could see it in /usr/lib/python3.4, but while trying to actually execute scripts with Python 3.5 I always got "ImportError: No module named 'requests'"
OK, so I figured, perhaps that's because the pack... | 2016/04/05 | [
"https://Stackoverflow.com/questions/36426547",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4680896/"
] | **First of all, it is a very bad idea to remove your *system* Python 3 in Ubuntu (which 3.4 is in recent
subrevisions of Trusty LTS)**. That is because it is a **vital part of the system**. If you run the command `apt-cache rdepends python3`, you'd see that packages such as `ubuntu-minimal`, `ubuntu-release-upgrader-co... | 1. Open a text-only virtual console by using the keyboard shortcut `Ctrl` + `Alt` + `F3`.
2. At the `login:` prompt type your username and press `Enter`.
3. At the `Password:` prompt type your user password and press `Enter`.
4. Reinstall the default Python 3 version by running the following command:
```
sudo apt inst... |
6,397,344 | it is a python code..whether implementing using linked list .... is efficient in this way...........
```
data = [] # data storage for stacks represented as linked lists
stack = [-1, -1, -1] # pointers to each of three stacks (-1 is the "null" pointer)
free = -1 # pointer to list of free stack nod... | 2011/06/18 | [
"https://Stackoverflow.com/questions/6397344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/804287/"
] | In python, a list is a stack:
```
>>> l = [1, 2, 3, 4, 5]
>>> l.pop()
5
>>> l.pop()
4
>>> l.append(9)
>>> l
[1, 2, 3, 9]
>>> l.pop()
9
>>> l.pop()
3
>>> l.append(12)
>>> l
[1, 2, 12]
```
Although it may be an... entertaining exercise to implement a c-style linked list in python, it is unnecessary, and likely to be v... | A far better solution could be using list instead of stack to implement linked list. The code given is stack implementation of linked list, which I believe is a norm in python but in C/C++ you can use list for efficient implementation.
A sample code in C would be as follows :-
```
#include <stdio.h>
#include <stdlib.... |
6,397,344 | it is a python code..whether implementing using linked list .... is efficient in this way...........
```
data = [] # data storage for stacks represented as linked lists
stack = [-1, -1, -1] # pointers to each of three stacks (-1 is the "null" pointer)
free = -1 # pointer to list of free stack nod... | 2011/06/18 | [
"https://Stackoverflow.com/questions/6397344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/804287/"
] | In python, a list is a stack:
```
>>> l = [1, 2, 3, 4, 5]
>>> l.pop()
5
>>> l.pop()
4
>>> l.append(9)
>>> l
[1, 2, 3, 9]
>>> l.pop()
9
>>> l.pop()
3
>>> l.append(12)
>>> l
[1, 2, 12]
```
Although it may be an... entertaining exercise to implement a c-style linked list in python, it is unnecessary, and likely to be v... | ```
def finding_element(a,k):
print a
i = 0
while k < a[i]:
i = i-1
print k,a[i]
if k > a[i]:
i = i+1
print k,a[i]
if k == a[i]:
print k,a[i]
else:
print "not found"
a = [ 1,3,5,7,8,9]
k = 5
finding_element(a,k)
``` |
6,397,344 | it is a python code..whether implementing using linked list .... is efficient in this way...........
```
data = [] # data storage for stacks represented as linked lists
stack = [-1, -1, -1] # pointers to each of three stacks (-1 is the "null" pointer)
free = -1 # pointer to list of free stack nod... | 2011/06/18 | [
"https://Stackoverflow.com/questions/6397344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/804287/"
] | In python, a list is a stack:
```
>>> l = [1, 2, 3, 4, 5]
>>> l.pop()
5
>>> l.pop()
4
>>> l.append(9)
>>> l
[1, 2, 3, 9]
>>> l.pop()
9
>>> l.pop()
3
>>> l.append(12)
>>> l
[1, 2, 12]
```
Although it may be an... entertaining exercise to implement a c-style linked list in python, it is unnecessary, and likely to be v... | You really don't have to go to all that trouble when Python does all of that out of the box. Sure you can wrap it in functions if you have some complex object to manipulate but don't overthink it and let Python worry about memory allocation (nobody does that manually anymore).
Here is the equivalent of all your functi... |
6,397,344 | it is a python code..whether implementing using linked list .... is efficient in this way...........
```
data = [] # data storage for stacks represented as linked lists
stack = [-1, -1, -1] # pointers to each of three stacks (-1 is the "null" pointer)
free = -1 # pointer to list of free stack nod... | 2011/06/18 | [
"https://Stackoverflow.com/questions/6397344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/804287/"
] | A far better solution could be using list instead of stack to implement linked list. The code given is stack implementation of linked list, which I believe is a norm in python but in C/C++ you can use list for efficient implementation.
A sample code in C would be as follows :-
```
#include <stdio.h>
#include <stdlib.... | ```
def finding_element(a,k):
print a
i = 0
while k < a[i]:
i = i-1
print k,a[i]
if k > a[i]:
i = i+1
print k,a[i]
if k == a[i]:
print k,a[i]
else:
print "not found"
a = [ 1,3,5,7,8,9]
k = 5
finding_element(a,k)
``` |
6,397,344 | it is a python code..whether implementing using linked list .... is efficient in this way...........
```
data = [] # data storage for stacks represented as linked lists
stack = [-1, -1, -1] # pointers to each of three stacks (-1 is the "null" pointer)
free = -1 # pointer to list of free stack nod... | 2011/06/18 | [
"https://Stackoverflow.com/questions/6397344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/804287/"
] | A far better solution could be using list instead of stack to implement linked list. The code given is stack implementation of linked list, which I believe is a norm in python but in C/C++ you can use list for efficient implementation.
A sample code in C would be as follows :-
```
#include <stdio.h>
#include <stdlib.... | You really don't have to go to all that trouble when Python does all of that out of the box. Sure you can wrap it in functions if you have some complex object to manipulate but don't overthink it and let Python worry about memory allocation (nobody does that manually anymore).
Here is the equivalent of all your functi... |
28,223,747 | I'm new to python and want help cleaning up my code.
I had to make a definition that takes a string and returns the first half lowercase and second part uppercase.
This is my code - but I can't help think there's a cleaner way to write this.
```
def sillycase(string):
x = len(string)/2
y = round(x)
print... | 2015/01/29 | [
"https://Stackoverflow.com/questions/28223747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4459432/"
] | You can use `find -exec` for this:
```
find /FolderA -type f -exec sed -i 's/wordA/wordB/g' {} +
``` | `find` would be the way to go.
A bash alternative:
```
shopt -s globstar
files=()
for file in FolderA/**; do # double asterisk is not a typo
[[ -f "$file" ]] && files+=("$file")
done
sed -i 's/wordA/wordB/g' "${files[@]}"
``` |
55,454,514 | I'm using a Kubernetes inventory builder script found here: <https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py>
On `line 36`, the ruamel YML library is imported using the code `from ruamel.yaml import YAML`. This library can be found here: <https://pypi.org/project/ruamel.... | 2019/04/01 | [
"https://Stackoverflow.com/questions/55454514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864245/"
] | `pip` is set to point to the Python 2 installation. To install the library under Python 3, do `pip3 install ruamel.yml`. | you're using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library. |
55,454,514 | I'm using a Kubernetes inventory builder script found here: <https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py>
On `line 36`, the ruamel YML library is imported using the code `from ruamel.yaml import YAML`. This library can be found here: <https://pypi.org/project/ruamel.... | 2019/04/01 | [
"https://Stackoverflow.com/questions/55454514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864245/"
] | In my case, I was installing this with `pip3 install ruamel.yaml`, and it was puting the package in `/usr/local/lib/python3.9/site-packages/`, but the `python3` binary on the machine was pinned to Python 3.7, so trying to import that module was sending the `ModuleNotFoundError` message.
What helped to fix this, was to... | you're using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library. |
55,454,514 | I'm using a Kubernetes inventory builder script found here: <https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py>
On `line 36`, the ruamel YML library is imported using the code `from ruamel.yaml import YAML`. This library can be found here: <https://pypi.org/project/ruamel.... | 2019/04/01 | [
"https://Stackoverflow.com/questions/55454514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864245/"
] | you're using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library. | This helped me (adding version number to python):
```
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[@]}
``` |
55,454,514 | I'm using a Kubernetes inventory builder script found here: <https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py>
On `line 36`, the ruamel YML library is imported using the code `from ruamel.yaml import YAML`. This library can be found here: <https://pypi.org/project/ruamel.... | 2019/04/01 | [
"https://Stackoverflow.com/questions/55454514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864245/"
] | `pip` is set to point to the Python 2 installation. To install the library under Python 3, do `pip3 install ruamel.yml`. | In my case, I was installing this with `pip3 install ruamel.yaml`, and it was puting the package in `/usr/local/lib/python3.9/site-packages/`, but the `python3` binary on the machine was pinned to Python 3.7, so trying to import that module was sending the `ModuleNotFoundError` message.
What helped to fix this, was to... |
55,454,514 | I'm using a Kubernetes inventory builder script found here: <https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py>
On `line 36`, the ruamel YML library is imported using the code `from ruamel.yaml import YAML`. This library can be found here: <https://pypi.org/project/ruamel.... | 2019/04/01 | [
"https://Stackoverflow.com/questions/55454514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864245/"
] | `pip` is set to point to the Python 2 installation. To install the library under Python 3, do `pip3 install ruamel.yml`. | This helped me (adding version number to python):
```
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[@]}
``` |
55,454,514 | I'm using a Kubernetes inventory builder script found here: <https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py>
On `line 36`, the ruamel YML library is imported using the code `from ruamel.yaml import YAML`. This library can be found here: <https://pypi.org/project/ruamel.... | 2019/04/01 | [
"https://Stackoverflow.com/questions/55454514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864245/"
] | In my case, I was installing this with `pip3 install ruamel.yaml`, and it was puting the package in `/usr/local/lib/python3.9/site-packages/`, but the `python3` binary on the machine was pinned to Python 3.7, so trying to import that module was sending the `ModuleNotFoundError` message.
What helped to fix this, was to... | This helped me (adding version number to python):
```
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[@]}
``` |
466,321 | How can I convert from a unix timestamp (say 1232559922) to a fractional julian date (2454853.03150).
I found a website ( <http://aa.usno.navy.mil/data/docs/JulianDate.php> ) that performs a similar calculation but I need to do it programatically.
Solutions can be in C/C++, python, perl, bash, etc... | 2009/01/21 | [
"https://Stackoverflow.com/questions/466321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/280/"
] | The Unix epoch (zero-point) is January 1, 1970 GMT. That corresponds to the Julian day of 2440587.5
So, in pseudo-code:
```
function float getJulianFromUnix( int unixSecs )
{
return ( unixSecs / 86400.0 ) + 2440587.5;
}
``` | I know that this is an old post, but I'll just say ...
The answer given by Jason Cohen is a good approximation of the conversion.
There is a problem though that relates to the number of seconds in one day. A day is not -exactly- 86400 seconds long, and periodically seconds are added to days in order to keep time sync... |
466,321 | How can I convert from a unix timestamp (say 1232559922) to a fractional julian date (2454853.03150).
I found a website ( <http://aa.usno.navy.mil/data/docs/JulianDate.php> ) that performs a similar calculation but I need to do it programatically.
Solutions can be in C/C++, python, perl, bash, etc... | 2009/01/21 | [
"https://Stackoverflow.com/questions/466321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/280/"
] | The Unix epoch (zero-point) is January 1, 1970 GMT. That corresponds to the Julian day of 2440587.5
So, in pseudo-code:
```
function float getJulianFromUnix( int unixSecs )
{
return ( unixSecs / 86400.0 ) + 2440587.5;
}
``` | Here is my JavaScript code to convert *Unix* timestamp to *Julian*. Originally is showing the current date and time, but with a little mod is answer to your question:
```js
function computeJulianDate(DD,MM,YY,HR,MN,SC) {
with (Math) {
HR = HR + (MN / 60) + (SC/3600);
GGG = 1;
if (YY <= 1585... |
466,321 | How can I convert from a unix timestamp (say 1232559922) to a fractional julian date (2454853.03150).
I found a website ( <http://aa.usno.navy.mil/data/docs/JulianDate.php> ) that performs a similar calculation but I need to do it programatically.
Solutions can be in C/C++, python, perl, bash, etc... | 2009/01/21 | [
"https://Stackoverflow.com/questions/466321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/280/"
] | The Unix epoch (zero-point) is January 1, 1970 GMT. That corresponds to the Julian day of 2440587.5
So, in pseudo-code:
```
function float getJulianFromUnix( int unixSecs )
{
return ( unixSecs / 86400.0 ) + 2440587.5;
}
``` | This question was asked over 13 years ago as of writing. That's pretty wild. Thanks to eapo's JS formula I converted it to PineScript v5 and in testing its at least really close. I don't think perfect accuracy would even be relevant for most (if any) TradingView applications. So, I didn't go as far as to ensure perfect... |
466,321 | How can I convert from a unix timestamp (say 1232559922) to a fractional julian date (2454853.03150).
I found a website ( <http://aa.usno.navy.mil/data/docs/JulianDate.php> ) that performs a similar calculation but I need to do it programatically.
Solutions can be in C/C++, python, perl, bash, etc... | 2009/01/21 | [
"https://Stackoverflow.com/questions/466321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/280/"
] | I know that this is an old post, but I'll just say ...
The answer given by Jason Cohen is a good approximation of the conversion.
There is a problem though that relates to the number of seconds in one day. A day is not -exactly- 86400 seconds long, and periodically seconds are added to days in order to keep time sync... | Here is my JavaScript code to convert *Unix* timestamp to *Julian*. Originally is showing the current date and time, but with a little mod is answer to your question:
```js
function computeJulianDate(DD,MM,YY,HR,MN,SC) {
with (Math) {
HR = HR + (MN / 60) + (SC/3600);
GGG = 1;
if (YY <= 1585... |
466,321 | How can I convert from a unix timestamp (say 1232559922) to a fractional julian date (2454853.03150).
I found a website ( <http://aa.usno.navy.mil/data/docs/JulianDate.php> ) that performs a similar calculation but I need to do it programatically.
Solutions can be in C/C++, python, perl, bash, etc... | 2009/01/21 | [
"https://Stackoverflow.com/questions/466321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/280/"
] | I know that this is an old post, but I'll just say ...
The answer given by Jason Cohen is a good approximation of the conversion.
There is a problem though that relates to the number of seconds in one day. A day is not -exactly- 86400 seconds long, and periodically seconds are added to days in order to keep time sync... | This question was asked over 13 years ago as of writing. That's pretty wild. Thanks to eapo's JS formula I converted it to PineScript v5 and in testing its at least really close. I don't think perfect accuracy would even be relevant for most (if any) TradingView applications. So, I didn't go as far as to ensure perfect... |
24,235,241 | I recently installed sublime text 2 to try it out before I decide to get sublime text 3 but I can't properly run any code from it. I've hit Ctrl + B and I get an output like this.
```
[Error 2] The system cannot find the file specified
[cmd: [u'python', u'-u', u'C:\\Users\\Jeff\\Desktop\\Personal codes\\print.py']]
[... | 2014/06/16 | [
"https://Stackoverflow.com/questions/24235241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3697905/"
] | Instead of adding python to the path, I prefer simply specifying the full path to python in the sublime build. Python.exe is probably installed in one of these (or something similar)
```
C:/Python
C:/Program Files/Python
C:/Program Files (x86)/Python
etc...
```
Once you found it (lets say its in C:\Program Files (x8... | Windows is unable to find your python installation. When you run a command like:
```
python <your_file.py>
```
the first `python` tells your system to find wherever your python binary is and try to run some command by that name. By looking over the path that was echoed, it doesn't look like you actually have your py... |
35,931,198 | I searched the forum and all answers are python or C+ related, this is for ruby.
I'm trying to figure out how to make the below program prompt the user for an item in the array by typing a number 1-4 (so the position wouldn't start from 0 in the users eyes).
It's probably a simple fix, but I am new to this.. I appreci... | 2016/03/11 | [
"https://Stackoverflow.com/questions/35931198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5281054/"
] | You can try something like this:
```
array = []
puts "please add to the array 4 times"
4.times do
array << gets.chomp
end
puts "#{array}"
loop do
puts "Select a position in the array by typing a singular number from 1-4"
ans = gets.chomp.to_i
if ans > 0 && ans <= array.length
puts "The element at posit... | You can get the index by combining `gets.chomp` (reads a line of user input and removes the trailing newline character) and `to_i` (convert to integer).
Combine this with the ability to access an array's element at a specific index using the `array[index_integer]` method.
To piece it together:
```
array = ["first_it... |
17,806,673 | Is there a canonical location where to put self-written packages? My own search only yielded a blog post about [where to put version-independent pure Python packages](http://pythonsimple.noucleus.net/python-install/python-site-packages-what-they-are-and-where-to-put-them) and a [SO question for the canonical location u... | 2013/07/23 | [
"https://Stackoverflow.com/questions/17806673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2375855/"
] | Thanks to the [two](http://docs.python.org/2/install/#how-installation-works) [additional](http://docs.python.org/2/install/#alternate-installation-the-home-scheme) links, I found not only the intended answer to my question, but also a solution that I like even more and that - ironically - was also explained in my firs... | I'd use the home scheme for this:
<http://docs.python.org/2/install/#alternate-installation-the-home-scheme> |
17,806,673 | Is there a canonical location where to put self-written packages? My own search only yielded a blog post about [where to put version-independent pure Python packages](http://pythonsimple.noucleus.net/python-install/python-site-packages-what-they-are-and-where-to-put-them) and a [SO question for the canonical location u... | 2013/07/23 | [
"https://Stackoverflow.com/questions/17806673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2375855/"
] | Place the source of your package wherever you'd like, but at least give your package a minimal `setup.py` file, immediately outside the package:
```
import setuptools
setuptools.setup(name='mypackage')
```
Then fake-install your package into your python install's `site-packages` by running:
```
python setup.py dev... | I'd use the home scheme for this:
<http://docs.python.org/2/install/#alternate-installation-the-home-scheme> |
17,806,673 | Is there a canonical location where to put self-written packages? My own search only yielded a blog post about [where to put version-independent pure Python packages](http://pythonsimple.noucleus.net/python-install/python-site-packages-what-they-are-and-where-to-put-them) and a [SO question for the canonical location u... | 2013/07/23 | [
"https://Stackoverflow.com/questions/17806673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2375855/"
] | Thanks to the [two](http://docs.python.org/2/install/#how-installation-works) [additional](http://docs.python.org/2/install/#alternate-installation-the-home-scheme) links, I found not only the intended answer to my question, but also a solution that I like even more and that - ironically - was also explained in my firs... | Place the source of your package wherever you'd like, but at least give your package a minimal `setup.py` file, immediately outside the package:
```
import setuptools
setuptools.setup(name='mypackage')
```
Then fake-install your package into your python install's `site-packages` by running:
```
python setup.py dev... |
17,806,673 | Is there a canonical location where to put self-written packages? My own search only yielded a blog post about [where to put version-independent pure Python packages](http://pythonsimple.noucleus.net/python-install/python-site-packages-what-they-are-and-where-to-put-them) and a [SO question for the canonical location u... | 2013/07/23 | [
"https://Stackoverflow.com/questions/17806673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2375855/"
] | Thanks to the [two](http://docs.python.org/2/install/#how-installation-works) [additional](http://docs.python.org/2/install/#alternate-installation-the-home-scheme) links, I found not only the intended answer to my question, but also a solution that I like even more and that - ironically - was also explained in my firs... | I had the same question, and your answer is very helpful.
To add a little bit, I came across this example that's helpful to me:
<http://python-packaging.readthedocs.io/en/latest/minimal.html>
It is a minimal example of how to package your own code, and properly install it locally (I imagine this is what you actually... |
17,806,673 | Is there a canonical location where to put self-written packages? My own search only yielded a blog post about [where to put version-independent pure Python packages](http://pythonsimple.noucleus.net/python-install/python-site-packages-what-they-are-and-where-to-put-them) and a [SO question for the canonical location u... | 2013/07/23 | [
"https://Stackoverflow.com/questions/17806673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2375855/"
] | Place the source of your package wherever you'd like, but at least give your package a minimal `setup.py` file, immediately outside the package:
```
import setuptools
setuptools.setup(name='mypackage')
```
Then fake-install your package into your python install's `site-packages` by running:
```
python setup.py dev... | I had the same question, and your answer is very helpful.
To add a little bit, I came across this example that's helpful to me:
<http://python-packaging.readthedocs.io/en/latest/minimal.html>
It is a minimal example of how to package your own code, and properly install it locally (I imagine this is what you actually... |
25,403,110 | I am getting started with Django through [this](http://www.youtube.com/watch?v=3DccH9AMwFQ) beautiful video tutorial.On Tutorial 15 of the video series, there is database migration using **south**. But when I do `python manage.py migrate signups`, I got a whole lot of errors. The first error was:
```
File "C:\Pytho... | 2014/08/20 | [
"https://Stackoverflow.com/questions/25403110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2673433/"
] | There's that problem, you use boolean as a default value (see `default=True` on line 19 in your migration) for `DateTime` column. That wont work. Just remove that `default=True` from your model and regenerate your migration.
You would probably need `null=True` in that column or some time-based default value. | In your migration the `fields.DateTimeField` can not be a Boolean value (default=True).
You can edit your migrations set a datetime value
```
import datetime
...
default = datetime.datetime(2016,2,25,16,35,658000)
...
```
The `models.DateTimeField` should be a `None` or a `datetime` object |
28,779,395 | This is a very easy code to understand things :
Main :
```html
import pdb
#pdb.set_trace()
import sys
import csv
sys.version_info
if sys.version_info[0] < 3:
from Tkinter import *
else:
from tkinter import *
from Untitled import *
main_window =Tk()
main_window.title("Welcome")
label = Label(main_... | 2015/02/28 | [
"https://Stackoverflow.com/questions/28779395",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4502651/"
] | The `command` lambda does not take any arguments at all; furthermore there is no `evt` that you can catch. A lambda can refer to variables outside it; this is called a closure. Thus your button code should be:
```
bouton1 = Button(main_window, text="Enter",
command = lambda: get(Current_Weight, entree1))
```
And... | Actually, you just need the Entry object entree1 as the lamda pass-in argument. Either statement below would work.
```
bouton1 = Button(main_window, text="Enter", command=lambda x = entree1: get(x))
bouton1 = Button(main_window, text="Enter", command=lambda : get(entree1))
```
with the function get defined as
```
... |
17,349,928 | I understand that an RGB to HSV conversion should take RGB values 0-255 and convert to HSV values [0-360, 0-1, 0-1]. For example see this [converter in java](http://www.javascripter.net/faq/rgb2hsv.htm):
When I run matplotlib.colors.rbg\_to\_hsv on an image, it seems to output values [0-1, 0-1, 0-360] instead. Howeve... | 2013/06/27 | [
"https://Stackoverflow.com/questions/17349928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1276299/"
] | It works beautifully if, instead of unsigned int RGB values from 0 to 255, you feed it float RGB values from 0 to 1. It would be nice if the documentation specified this, or if the function tried to catch what seems to be a very likely human error. But you can get what you want simply by calling:
```
print colors.rgb_... | Take care, the source comment states input/output should be of dimension M,N,3, and the function fails for RGBA (M,N,4) images, e.g. imported png files. |
65,408,099 | When i was practising list&if in python i got stuck with a problem
```
friends=["a","b","c"]
print("eklemek mi cikarmak mi istiyosunuz ?")
ans=(input())
if ans == 'add':
add=input("adding who ?")
friends.append(add)
if ans=='remove':
remove = input("removing who ?")
friends.remove(remove)
print(remove)
```
... | 2020/12/22 | [
"https://Stackoverflow.com/questions/65408099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14871427/"
] | We had the same issue, and managed to fix it by searching for the exact minified function in the minified code (in this case `(0,o.useState`), then search around that code to find some string or identifier that wasn't minifed (found a prop name that was a string) that we could use to find the place in the source code.
... | I had a similar problem,
I've realized that my Expo SDK version was an older one, I've upgraded Expo SDK and re-deployed my app, problem did not occur again. |
57,774,652 | This function:
```js
function print(){
console.log('num 1')
setTimeout(() => {
global.name = 'max'
console.log('num 2')
},9000);
console.log('num 3');
}
print();
console.log(global.name)
```
is priting this:
```
num 1
num 3
undefined
num 2
```
And I need to:
1. print `num 1`
2. wait untill the ... | 2019/09/03 | [
"https://Stackoverflow.com/questions/57774652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10489311/"
] | The error is cause by this line:
```
options['partitionKey'] = '/Structures'
```
You need to specify the specific value of partition key here, not the column name.For example,my partition key is '/name',and the specific value in this document is 'A'.
[
database = client.get_database_client(DATABASE_NAME)
container =... |
39,875,273 | I have attempted to create an insertion sort in python, however the list returned is not sorted. What is the problem with my code?
Argument given: [3, 2, 1, 4, 5, 8, 7, 9, 6]
Result: 2
1
3
6
4
7
5
8
9
Python code:
```
def insertion_sort(mylist):
sorted_list = []
for i in mylist:
posfound = 0 #defaul... | 2016/10/05 | [
"https://Stackoverflow.com/questions/39875273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4363434/"
] | You need to change `sorted_list.insert(j-1, i)` to be `sorted_list.insert(j, i)` to insert before position `j`.
`insert(j-1, ..)` will insert before the *previous* element, and in the case where `j=0` it'll wrap around and insert before the last element.
The [Python data structures tutorial](https://docs.python.org... | As often, it was a off-by-one error, the code below is fixed. I also made some parts a bit prettier.
```
def insertion_sort(mylist):
sorted_list = []
for i in mylist:
for index, j in enumerate(sorted_list):
if j > i:
sorted_list.insert(index, i) #put the number in before ele... |
39,875,273 | I have attempted to create an insertion sort in python, however the list returned is not sorted. What is the problem with my code?
Argument given: [3, 2, 1, 4, 5, 8, 7, 9, 6]
Result: 2
1
3
6
4
7
5
8
9
Python code:
```
def insertion_sort(mylist):
sorted_list = []
for i in mylist:
posfound = 0 #defaul... | 2016/10/05 | [
"https://Stackoverflow.com/questions/39875273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4363434/"
] | You need to change `sorted_list.insert(j-1, i)` to be `sorted_list.insert(j, i)` to insert before position `j`.
`insert(j-1, ..)` will insert before the *previous* element, and in the case where `j=0` it'll wrap around and insert before the last element.
The [Python data structures tutorial](https://docs.python.org... | As Efferalgan & tzaman have mentioned your core problem is due to an off-by-one error. To catch these sorts of errors it's useful to print `i`, `j` and `sorted_list` on each loop iteration to make sure they contain what you think they contain.
Here are a few versions of your algorithm. First, a repaired version of you... |
39,875,273 | I have attempted to create an insertion sort in python, however the list returned is not sorted. What is the problem with my code?
Argument given: [3, 2, 1, 4, 5, 8, 7, 9, 6]
Result: 2
1
3
6
4
7
5
8
9
Python code:
```
def insertion_sort(mylist):
sorted_list = []
for i in mylist:
posfound = 0 #defaul... | 2016/10/05 | [
"https://Stackoverflow.com/questions/39875273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4363434/"
] | As Efferalgan & tzaman have mentioned your core problem is due to an off-by-one error. To catch these sorts of errors it's useful to print `i`, `j` and `sorted_list` on each loop iteration to make sure they contain what you think they contain.
Here are a few versions of your algorithm. First, a repaired version of you... | As often, it was a off-by-one error, the code below is fixed. I also made some parts a bit prettier.
```
def insertion_sort(mylist):
sorted_list = []
for i in mylist:
for index, j in enumerate(sorted_list):
if j > i:
sorted_list.insert(index, i) #put the number in before ele... |
7,615,511 | I am writing a python script and I just need the second line of a series of very small text files. I would like to extract this without saving the file to my harddrive as I currently do.
I have found a few threads that reference the TempFile and StringIO modules but I was unable to make much sense of them.
Currently... | 2011/09/30 | [
"https://Stackoverflow.com/questions/7615511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/935684/"
] | There's a glitch in iText and iTextSharp but you can fix it pretty easily if you don't mind downloading the source and recompiling it. You need to make a change to two files. Any changes I've made are commented inline in the code. Line numbers are based on the 5.1.2.0 code rev 240
The first is in `iTextSharp.text.html... | I would recommend using [wkhtmltopdf](http://code.google.com/p/wkhtmltopdf/) instead of iText. wkhtmltopdf will output the html exactly as rendered by webkit (Google Chrome, Safari) instead of iText's conversion. It is just a binary that you can call. That being said, I might check the html to ensure that there are par... |
7,615,511 | I am writing a python script and I just need the second line of a series of very small text files. I would like to extract this without saving the file to my harddrive as I currently do.
I have found a few threads that reference the TempFile and StringIO modules but I was unable to make much sense of them.
Currently... | 2011/09/30 | [
"https://Stackoverflow.com/questions/7615511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/935684/"
] | Thanks for the help everyone. I was able to find a small work around by doing the following:
```
vsHTML.Replace(" ", " ").Replace(Chr(9), " ").Replace(Chr(160), " ").Replace(vbCrLf, "<br />")
```
The actual code does not display properly but, the first replace is replacing whi... | I would recommend using [wkhtmltopdf](http://code.google.com/p/wkhtmltopdf/) instead of iText. wkhtmltopdf will output the html exactly as rendered by webkit (Google Chrome, Safari) instead of iText's conversion. It is just a binary that you can call. That being said, I might check the html to ensure that there are par... |
7,615,511 | I am writing a python script and I just need the second line of a series of very small text files. I would like to extract this without saving the file to my harddrive as I currently do.
I have found a few threads that reference the TempFile and StringIO modules but I was unable to make much sense of them.
Currently... | 2011/09/30 | [
"https://Stackoverflow.com/questions/7615511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/935684/"
] | Thanks for the help everyone. I was able to find a small work around by doing the following:
```
vsHTML.Replace(" ", " ").Replace(Chr(9), " ").Replace(Chr(160), " ").Replace(vbCrLf, "<br />")
```
The actual code does not display properly but, the first replace is replacing whi... | There's a glitch in iText and iTextSharp but you can fix it pretty easily if you don't mind downloading the source and recompiling it. You need to make a change to two files. Any changes I've made are commented inline in the code. Line numbers are based on the 5.1.2.0 code rev 240
The first is in `iTextSharp.text.html... |
65,470,264 | I am pretty new to python. Just been working through some online tutorials on udemy. I seem to have an issue with pip installing modules.
* I've tried reinstalling them.
* Upgrading my python version.
* In VS I always just get `module not found`.
If I do it in the cmd prompt this is what I get below.
[`, you will see the query plan, w... | You might want to repartition after running `special_rows = df.filter(col('special') > 0)`. There can be a large number of empty partitions after running a filtering operation, [as explained here](https://mungingdata.com/apache-spark/filter-where/).
The `new_df_1` will make cache `special_rows` which will be reused by... |
74,081,960 | I got my program running fine as explained at: [How can you make a micropython program on a raspberry pi pico autorun?](https://stackoverflow.com/questions/66183596/how-can-you-make-a-micropython-program-on-a-raspberry-pi-pico-autorun/74078142#74078142)
I'm installing a `main.py` that does:
```
import machine
import ... | 2022/10/15 | [
"https://Stackoverflow.com/questions/74081960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/895245/"
] | What appears to be happening here is that exiting `screen` (or exiting `picocom` without the tty reset) leaves the [`DTR`](https://en.wikipedia.org/wiki/Data_Terminal_Ready) line on the serial port high. We can verify this by writing some simple code to control the DTR line, like this:
```
#include <unistd.h>
#include... | I don't know why it works, but based on advie from larsks:
```
sudo apt install picocom
picocom /dev/ttyACM0
```
and then quit with Ctrl-A Ctrl-X (not Ctrl-A Ctrl-Q) does do what I want. Not sure what `screen` is doing differently exactly.
When quitting, Ctrl-Q shows on terminal:
```
Skipping tty reset...
```
an... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.