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
14,241,239
Can I have any highlight kind of things using Python 2.7? Say when my script clicking on the `submit button`,feeding data into the `text field` or selecting values from the `drop-down field`, just to highlight on that element to make sure to the script runner that his/her script doing what he/she wants. ***EDIT*** I ...
2013/01/09
[ "https://Stackoverflow.com/questions/14241239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2767755/" ]
This is something you need to do with javascript, not python.
***[NOTE: I'm leaving this answer for historical purposes but readers should note that the original question has changed from concerning itself with Python to concerning itself with Selenium]*** Assuming you're talking about a browser based application being served from a Python back-end server (and it's just a guess ...
26,691,784
Example: ``` class Planet(Enum): MERCURY = (mass: 3.303e+23, radius: 2.4397e6) def __init__(self, mass, radius): self.mass = mass # in kilograms self.radius = radius # in meters ``` Ref: <https://docs.python.org/3/library/enum.html#planet> Why do I want to do this? If there are a f...
2014/11/01
[ "https://Stackoverflow.com/questions/26691784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257299/" ]
While you can't use named arguments the way you describe with enums, you can get a similar effect with a [`namedtuple`](https://docs.python.org/3/library/collections.html#collections.namedtuple) mixin: ``` from collections import namedtuple from enum import Enum Body = namedtuple("Body", ["mass", "radius"]) class Pl...
The accepted answer by @zero-piraeus can be slightly extended to allow default arguments as well. This is very handy when you have a large enum with most entries having the same value for an element. ``` class Body(namedtuple('Body', "mass radius moons")): def __new__(cls, mass, radius, moons=0): return su...
26,691,784
Example: ``` class Planet(Enum): MERCURY = (mass: 3.303e+23, radius: 2.4397e6) def __init__(self, mass, radius): self.mass = mass # in kilograms self.radius = radius # in meters ``` Ref: <https://docs.python.org/3/library/enum.html#planet> Why do I want to do this? If there are a f...
2014/11/01
[ "https://Stackoverflow.com/questions/26691784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257299/" ]
While you can't use named arguments the way you describe with enums, you can get a similar effect with a [`namedtuple`](https://docs.python.org/3/library/collections.html#collections.namedtuple) mixin: ``` from collections import namedtuple from enum import Enum Body = namedtuple("Body", ["mass", "radius"]) class Pl...
If going beyond the `namedtuple` mix-in check out the [`aenum`](https://pypi.python.org/pypi/aenum) library1. Besides having a few extra bells and whistles for `Enum` it also supports `NamedConstant` and a metaclass-based `NamedTuple`. Using `aenum.Enum` the above code could look like: ``` from aenum import Enum, enu...
26,691,784
Example: ``` class Planet(Enum): MERCURY = (mass: 3.303e+23, radius: 2.4397e6) def __init__(self, mass, radius): self.mass = mass # in kilograms self.radius = radius # in meters ``` Ref: <https://docs.python.org/3/library/enum.html#planet> Why do I want to do this? If there are a f...
2014/11/01
[ "https://Stackoverflow.com/questions/26691784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257299/" ]
While you can't use named arguments the way you describe with enums, you can get a similar effect with a [`namedtuple`](https://docs.python.org/3/library/collections.html#collections.namedtuple) mixin: ``` from collections import namedtuple from enum import Enum Body = namedtuple("Body", ["mass", "radius"]) class Pl...
For Python 3.6.1+ the [typing.NamedTuple](https://docs.python.org/3.6/library/typing.html#typing.NamedTuple) can be used, which also allows for setting default values, which leads to prettier code. The example by @shao.lo then looks like this: ``` from enum import Enum from typing import NamedTuple class Body(NamedTu...
26,691,784
Example: ``` class Planet(Enum): MERCURY = (mass: 3.303e+23, radius: 2.4397e6) def __init__(self, mass, radius): self.mass = mass # in kilograms self.radius = radius # in meters ``` Ref: <https://docs.python.org/3/library/enum.html#planet> Why do I want to do this? If there are a f...
2014/11/01
[ "https://Stackoverflow.com/questions/26691784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257299/" ]
The accepted answer by @zero-piraeus can be slightly extended to allow default arguments as well. This is very handy when you have a large enum with most entries having the same value for an element. ``` class Body(namedtuple('Body', "mass radius moons")): def __new__(cls, mass, radius, moons=0): return su...
If going beyond the `namedtuple` mix-in check out the [`aenum`](https://pypi.python.org/pypi/aenum) library1. Besides having a few extra bells and whistles for `Enum` it also supports `NamedConstant` and a metaclass-based `NamedTuple`. Using `aenum.Enum` the above code could look like: ``` from aenum import Enum, enu...
26,691,784
Example: ``` class Planet(Enum): MERCURY = (mass: 3.303e+23, radius: 2.4397e6) def __init__(self, mass, radius): self.mass = mass # in kilograms self.radius = radius # in meters ``` Ref: <https://docs.python.org/3/library/enum.html#planet> Why do I want to do this? If there are a f...
2014/11/01
[ "https://Stackoverflow.com/questions/26691784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257299/" ]
The accepted answer by @zero-piraeus can be slightly extended to allow default arguments as well. This is very handy when you have a large enum with most entries having the same value for an element. ``` class Body(namedtuple('Body', "mass radius moons")): def __new__(cls, mass, radius, moons=0): return su...
For Python 3.6.1+ the [typing.NamedTuple](https://docs.python.org/3.6/library/typing.html#typing.NamedTuple) can be used, which also allows for setting default values, which leads to prettier code. The example by @shao.lo then looks like this: ``` from enum import Enum from typing import NamedTuple class Body(NamedTu...
26,691,784
Example: ``` class Planet(Enum): MERCURY = (mass: 3.303e+23, radius: 2.4397e6) def __init__(self, mass, radius): self.mass = mass # in kilograms self.radius = radius # in meters ``` Ref: <https://docs.python.org/3/library/enum.html#planet> Why do I want to do this? If there are a f...
2014/11/01
[ "https://Stackoverflow.com/questions/26691784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257299/" ]
For Python 3.6.1+ the [typing.NamedTuple](https://docs.python.org/3.6/library/typing.html#typing.NamedTuple) can be used, which also allows for setting default values, which leads to prettier code. The example by @shao.lo then looks like this: ``` from enum import Enum from typing import NamedTuple class Body(NamedTu...
If going beyond the `namedtuple` mix-in check out the [`aenum`](https://pypi.python.org/pypi/aenum) library1. Besides having a few extra bells and whistles for `Enum` it also supports `NamedConstant` and a metaclass-based `NamedTuple`. Using `aenum.Enum` the above code could look like: ``` from aenum import Enum, enu...
74,542,597
i have a a number of xml files with me, whose format is: ``` <objects> <object> <record> <invoice_source>EMAIL</invoice_source> <invoice_capture_date>2022-11-18</invoice_capture_date> <document_type>INVOICE</document_type> <data_capture_provider_code>00001</data_capture_pro...
2022/11/23
[ "https://Stackoverflow.com/questions/74542597", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20397498/" ]
So here is what I would do. Instead of controlling the stamina in multiple places and hve forth and back references (=dependencies) between all your scripts I would rather keep this authority within the `PlayerController`. Your `StaminaBar` component should be purely **listening** and visualizing the current value wi...
You're decreasing and increasing the stamina in the same scope. I think you should let the stamina to be drained when sprint is pressed and start regenerating only if it is released.
59,573,454
I am trying to find a simple way to calculate soft cosine similarity between two sentences. Here is my attempt and learning: ``` from gensim.matutils import softcossim sent_1 = 'Dravid is a cricket player and a opening batsman'.split() sent_2 = 'Leo is a cricket player too He is a batsman,baller and keeper'.split() ...
2020/01/03
[ "https://Stackoverflow.com/questions/59573454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4763959/" ]
As of the current version of Gensim, 3.8.3, some of the method calls from both the question and previous answers have been deprecated. Those functions deprecated have been removed from the 4.0.0 beta. Can't seem to provide code in a reply to @EliadL, so adding a new comment. The current method for solving this problem...
Going by [this tutorial](https://www.machinelearningplus.com/nlp/gensim-tutorial/#18howtocomputesimilaritymetricslikecosinesimilarityandsoftcosinesimilarity): ``` import gensim.downloader as api from gensim import corpora from gensim.matutils import softcossim sent_1 = 'Dravid is a cricket player and a opening batsma...
59,573,454
I am trying to find a simple way to calculate soft cosine similarity between two sentences. Here is my attempt and learning: ``` from gensim.matutils import softcossim sent_1 = 'Dravid is a cricket player and a opening batsman'.split() sent_2 = 'Leo is a cricket player too He is a batsman,baller and keeper'.split() ...
2020/01/03
[ "https://Stackoverflow.com/questions/59573454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4763959/" ]
Going by [this tutorial](https://www.machinelearningplus.com/nlp/gensim-tutorial/#18howtocomputesimilaritymetricslikecosinesimilarityandsoftcosinesimilarity): ``` import gensim.downloader as api from gensim import corpora from gensim.matutils import softcossim sent_1 = 'Dravid is a cricket player and a opening batsma...
You can use SoftCosineSimilarity class in gensim.similarities in gensim 4.0.0 upwards ``` from gensim.similarities import SoftCosineSimilarity #Calculate Soft Cosine Similarity between the query and the documents. def find_similarity(query,documents): query = dictionary.doc2bow(query) index = SoftCosineSimilarity(...
59,573,454
I am trying to find a simple way to calculate soft cosine similarity between two sentences. Here is my attempt and learning: ``` from gensim.matutils import softcossim sent_1 = 'Dravid is a cricket player and a opening batsman'.split() sent_2 = 'Leo is a cricket player too He is a batsman,baller and keeper'.split() ...
2020/01/03
[ "https://Stackoverflow.com/questions/59573454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4763959/" ]
As of the current version of Gensim, 3.8.3, some of the method calls from both the question and previous answers have been deprecated. Those functions deprecated have been removed from the 4.0.0 beta. Can't seem to provide code in a reply to @EliadL, so adding a new comment. The current method for solving this problem...
You can use SoftCosineSimilarity class in gensim.similarities in gensim 4.0.0 upwards ``` from gensim.similarities import SoftCosineSimilarity #Calculate Soft Cosine Similarity between the query and the documents. def find_similarity(query,documents): query = dictionary.doc2bow(query) index = SoftCosineSimilarity(...
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
``` class A: pass a = A() str(a.__class__) ``` The sample code above (when input in the interactive interpreter) will produce `'__main__.A'` as opposed to `'A'` which is produced if the `__name__` attribute is invoked. By simply passing the result of `A.__class__` to the `str` constructor the parsing is handled fo...
In Python 2, ``` type(instance).__name__ != instance.__class__.__name__ # if class A is defined like class A(): ... type(instance) == instance.__class__ # if class A is defined like class A(object): ... ``` Example: ``` >>> class aclass(object): ... pass ... >>> a = aclass() >>> type(a) <class '__main__.acl...
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
[`type()`](https://docs.python.org/3/library/functions.html#type) ? ``` >>> class A: ... def whoami(self): ... print(type(self).__name__) ... >>> >>> class B(A): ... pass ... >>> >>> >>> o = B() >>> o.whoami() 'B' >>> ```
Good question. Here's a simple example based on GHZ's which might help someone: ``` >>> class person(object): def init(self,name): self.name=name def info(self) print "My name is {0}, I am a {1}".format(self.name,self.__class__.__name__) >>> bob = person(name='Robert') >>> bob....
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
``` class A: pass a = A() str(a.__class__) ``` The sample code above (when input in the interactive interpreter) will produce `'__main__.A'` as opposed to `'A'` which is produced if the `__name__` attribute is invoked. By simply passing the result of `A.__class__` to the `str` constructor the parsing is handled fo...
To get instance classname: ```py type(instance).__name__ ``` or ```py instance.__class__.__name__ ``` both are the same
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
In Python 2, ``` type(instance).__name__ != instance.__class__.__name__ # if class A is defined like class A(): ... type(instance) == instance.__class__ # if class A is defined like class A(object): ... ``` Example: ``` >>> class aclass(object): ... pass ... >>> a = aclass() >>> type(a) <class '__main__.acl...
Apart from grabbing the special [`__name__`](https://docs.python.org/3/library/stdtypes.html#definition.__name__) attribute, you might find yourself in need of the [qualified name](https://www.python.org/dev/peps/pep-3155/) for a given class/function. This is done by grabbing the types `__qualname__`. In most cases, t...
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
Good question. Here's a simple example based on GHZ's which might help someone: ``` >>> class person(object): def init(self,name): self.name=name def info(self) print "My name is {0}, I am a {1}".format(self.name,self.__class__.__name__) >>> bob = person(name='Robert') >>> bob....
To get instance classname: ```py type(instance).__name__ ``` or ```py instance.__class__.__name__ ``` both are the same
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
To get instance classname: ```py type(instance).__name__ ``` or ```py instance.__class__.__name__ ``` both are the same
You can first use `type` and then `str` to extract class name from it. ```py class foo:pass; bar:foo=foo(); print(str(type(bar))[8:-2][len(str(type(bar).__module__))+1:]); ``` Result ------ ``` foo ```
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
``` class A: pass a = A() str(a.__class__) ``` The sample code above (when input in the interactive interpreter) will produce `'__main__.A'` as opposed to `'A'` which is produced if the `__name__` attribute is invoked. By simply passing the result of `A.__class__` to the `str` constructor the parsing is handled fo...
Alternatively you can use the `classmethod` decorator: ```python class A: @classmethod def get_classname(cls): return cls.__name__ def use_classname(self): return self.get_classname() ``` **Usage**: ```python >>> A.get_classname() 'A' >>> a = A() >>> a.get_classname() 'A' >>> a.use_clas...
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
Have you tried the [`__name__` attribute](https://docs.python.org/library/stdtypes.html#definition.__name__) of the class? ie `type(x).__name__` will give you the name of the class, which I think is what you want. ``` >>> import itertools >>> x = itertools.count(0) >>> type(x).__name__ 'count' ``` If you're still us...
Alternatively you can use the `classmethod` decorator: ```python class A: @classmethod def get_classname(cls): return cls.__name__ def use_classname(self): return self.get_classname() ``` **Usage**: ```python >>> A.get_classname() 'A' >>> a = A() >>> a.get_classname() 'A' >>> a.use_clas...
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
Do you want the name of the class as a string? ``` instance.__class__.__name__ ```
You can simply use `__qualname__` which stands for qualified name of a function or class Example: ``` >>> class C: ... class D: ... def meth(self): ... pass ... >>> C.__qualname__ 'C' >>> C.D.__qualname__ 'C.D' >>> C.D.meth.__qualname__ 'C.D.meth' ``` documentation link [**qualname**](https:...
510,972
How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the [`inspect`](https://docs.python.org/2/library/inspect.html "inspect — Inspect live objects") module or parse the `__class__` attribute.
2009/02/04
[ "https://Stackoverflow.com/questions/510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
Have you tried the [`__name__` attribute](https://docs.python.org/library/stdtypes.html#definition.__name__) of the class? ie `type(x).__name__` will give you the name of the class, which I think is what you want. ``` >>> import itertools >>> x = itertools.count(0) >>> type(x).__name__ 'count' ``` If you're still us...
To get instance classname: ```py type(instance).__name__ ``` or ```py instance.__class__.__name__ ``` both are the same
70,014,480
I've been hosting my static site via an google app engine standard python setup for years without a problem. Today I started seeing the error below. Note: there used to be a page on GCP explaining how to host a static page using python GAE standard, but I can't find it now. Is it maybe the case where now it's recommend...
2021/11/18
[ "https://Stackoverflow.com/questions/70014480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10458445/" ]
This error only happened on Nov 17th and has since not happened again, without any changes by me. Perhaps it was related to something under-the-hood on google app engine servers.
Note that you are using Python 3.8 as per your `app.yaml` file, and the document you have shared is for Python 2.7. As Python 2 is no longer supported, migrating from Python 2 to Python 3 runtime will help you remove the error. The documentation [here](https://cloud.google.com/appengine/docs/standard/python/migrate-to...
50,996,060
I'm trying to use ruamel.yaml to modify an AWS CloudFormation template on the fly using python. I added the following code to make the safe\_load working with CloudFormation functions such as `!Ref`. However, when I dump them out, those values with !Ref (or any other functions) will be wrapped by quotes. CloudFormation...
2018/06/22
[ "https://Stackoverflow.com/questions/50996060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3209177/" ]
Essentially you tweak the loader, to load tagged (scalar) objects as if they were mappings, with the tag the key and the value the scalar. But you don't do anything to distinguish the `dict` loaded from such a mapping from other dicts loaded from normal mappings, nor do you have any specific code to represent such a ma...
Apart from Anthon's detailed answer above, for the specific question in terms of CloudFormation template, I found another very quick & sweet workaround. Still using the constructor snippet to load the YAML. ``` def funcparse(loader, node): node.value = { ruamel.yaml.ScalarNode: loader.construct_scalar, ...
62,585,490
TF 2.3.0.dev20200620 I got this error during .fit(...) for a model with a sigmoid binary output. I used tf.data.Dataset as the input pipeline. The strange thing is it depends on the metric: Don't work: ``` model.compile( optimizer=tf.keras.optimizers.Adam(lr=1e-4, decay=1e-6), loss=tf.keras.losses.BinaryCros...
2020/06/25
[ "https://Stackoverflow.com/questions/62585490", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1762295/" ]
Had exactly the same problem when using 'accuracy' metric. I followed <https://github.com/tensorflow/tensorflow/issues/32912#issuecomment-550363802> example: ``` def _fixup_shape(images, labels, weights): images.set_shape([None, None, None, 3]) labels.set_shape([None, 19]) # I have 19 classes weights.set_...
I am able to fix this in such a way as to keep the metrics 'accuracy' (rather than using BinaryAccuracy). However, I do not quite understand why this is needed for 'accuracy', but not needed for other closely related one (e.g. BinaryAccuracy). 2 things: 1. construct a ds such that the batch label has shape of (batch\...
49,989,188
I have function like this one: ``` def get_list_of_movies(table): #some code here print(a_list) return a_list ``` Reason why I want to use print and return is that I'm using this function in many places. So after calling this function from menu I want to get printed list of content. This same functio...
2018/04/23
[ "https://Stackoverflow.com/questions/49989188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8773813/" ]
Add a separate argument with a default value of `None` to control the printing. Pass ``` def get_list_of_movies(table, printIt=False): ... if printIt: print(a_list) return a_list ... movies = get_list_of_movies(table, printIt=True) ``` Another approach is to pass `print` itself as the argument,...
A completely different approach is to *always* print the list, but control where it gets printed *to*: ``` def get_list_of_movies(table, print_to=os.devnull): ... print(a_list, file=location) return a_list movies = get_list_of_movies(table, print_to=sys.stdout) ``` The `print_to` argument can be any fi...
11,882,194
I have a django web application running on our **apache2** production server using **mod\_python**, but no static files are found (css,images ... ) All our static stuff is under `/var/my.site/example/static` ``` /var/my.site/example/static/ |-admin/ |-css/ ...
2012/08/09
[ "https://Stackoverflow.com/questions/11882194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/481406/" ]
After @supervacuo suggestion that I strip down everything from django, I got apache to serve the static files and realized what was wrong. The problem was that `<Location "/example">` got priority over `Alias /example/static`. It didn't matter where I put the `Alias` (above or below the `<Location> - tag`). To fix ...
Try to eliminate the problem step-by-step. Loading static files should work completely independently of Django. Try commenting out all lines relating to Django in your `VirtualHost` config. (Remember to reload Apache after changing the configuration) If that works, it may be that you need to take more steps to avoid ...
11,882,194
I have a django web application running on our **apache2** production server using **mod\_python**, but no static files are found (css,images ... ) All our static stuff is under `/var/my.site/example/static` ``` /var/my.site/example/static/ |-admin/ |-css/ ...
2012/08/09
[ "https://Stackoverflow.com/questions/11882194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/481406/" ]
Try to eliminate the problem step-by-step. Loading static files should work completely independently of Django. Try commenting out all lines relating to Django in your `VirtualHost` config. (Remember to reload Apache after changing the configuration) If that works, it may be that you need to take more steps to avoid ...
The only problem I can see is with this: `"GET /example/static/css/base.css/ HTTP/1.1" 500 756` Since `/base.css/` is not a valid link; it gets passed to django; and since it doesn't match a URL pattern it raises a 500. You should fix the template that has the errant `/`.
11,882,194
I have a django web application running on our **apache2** production server using **mod\_python**, but no static files are found (css,images ... ) All our static stuff is under `/var/my.site/example/static` ``` /var/my.site/example/static/ |-admin/ |-css/ ...
2012/08/09
[ "https://Stackoverflow.com/questions/11882194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/481406/" ]
After @supervacuo suggestion that I strip down everything from django, I got apache to serve the static files and realized what was wrong. The problem was that `<Location "/example">` got priority over `Alias /example/static`. It didn't matter where I put the `Alias` (above or below the `<Location> - tag`). To fix ...
The only problem I can see is with this: `"GET /example/static/css/base.css/ HTTP/1.1" 500 756` Since `/base.css/` is not a valid link; it gets passed to django; and since it doesn't match a URL pattern it raises a 500. You should fix the template that has the errant `/`.
61,966,894
So I was using flask\_login for my login system on my mac, and I seem to have run into a problem. When I ran the code, it says I have not set my secret key even if I had done so. My code was: ```py from flask import Flask, render_template, request, session, redirect, url_for, jsonify from flask_session import Session...
2020/05/23
[ "https://Stackoverflow.com/questions/61966894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13600242/" ]
As @Harmandeep Kalsi said in the comments, I added `app.config['SESSION_TYPE']` and it worked.
For anyone else that is still getting an error after the other answers, if you're using the format `app.confing['<string>']` make sure that you include the underscore between "SECRET" and "KEY". That ended up being my issue, but it results in the same error code so searching for it lead me here. So, I thought I'd prov...
11,170,414
I just upgraded from SnowLeapord to Lion and now cannot create virtualenvs. I understand that there are new Python installations after the upgrade and no site packages and have tried installing pip and virtualenv again as well as upgrading to Xcode4 but I always get this error: ``` ~ > virtualenv --distribute env New ...
2012/06/23
[ "https://Stackoverflow.com/questions/11170414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/883845/" ]
Turns out that although I upgraded Xcode to version 4, it does not automatically install the command line tools. I followed this <http://blog.cingusoft.org/mac-osx-lion-virtualenv-and-could-not-call-in>. Basically, install Xcode, go into Preferences and then Downloads and install "Command Line Tools". It works now. ...
I also had to upgrade my setuptools. `pip install setuptools --upgrade`
11,170,414
I just upgraded from SnowLeapord to Lion and now cannot create virtualenvs. I understand that there are new Python installations after the upgrade and no site packages and have tried installing pip and virtualenv again as well as upgrading to Xcode4 but I always get this error: ``` ~ > virtualenv --distribute env New ...
2012/06/23
[ "https://Stackoverflow.com/questions/11170414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/883845/" ]
Turns out that although I upgraded Xcode to version 4, it does not automatically install the command line tools. I followed this <http://blog.cingusoft.org/mac-osx-lion-virtualenv-and-could-not-call-in>. Basically, install Xcode, go into Preferences and then Downloads and install "Command Line Tools". It works now. ...
``` cd /usr/lib/python2.7 sudo ln -s plat-x86_64-linux-gnu/_sysconfigdata_nd.py . ```
57,151,931
I've created a python script together with selenium to parse a specific content from a webpage. I can get this result `AARONS INC` located under `QUOTE` in many different ways but the way I wish to scrape that is by using ***`pseudo selector`*** which unfortunately selenium doesn't support. The commented out line withi...
2019/07/22
[ "https://Stackoverflow.com/questions/57151931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7180194/" ]
This is one of the ways you can achieve that. Give it a shot. ``` from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait with webdriver.Chrome() as driver: wait = WebDriverWait(driver, 10) driver.get('https://www.nyse.com/quote/XNYS:AAN') item = wait.until( lambda ...
Here is the simple approach. ``` url = 'https://www.nyse.com/quote/XNYS:AAN' driver.get(url) # wait for the elment to be presented ele = WebDriverWait(driver, 30).until(lambda driver: driver.execute_script('''return $('span:contains("AARONS")')[0];''')) # print the text of the element print (ele.text) ```
57,151,931
I've created a python script together with selenium to parse a specific content from a webpage. I can get this result `AARONS INC` located under `QUOTE` in many different ways but the way I wish to scrape that is by using ***`pseudo selector`*** which unfortunately selenium doesn't support. The commented out line withi...
2019/07/22
[ "https://Stackoverflow.com/questions/57151931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7180194/" ]
You could do the while thing in the browser script which is probably safer: ``` item = driver.execute_async_script(""" var span, interval = setInterval(() => { if(span = $('span:contains("AARONS")')[0]){ clearInterval(interval) arguments[0](span) } }, 1000) """) ```
Here is the simple approach. ``` url = 'https://www.nyse.com/quote/XNYS:AAN' driver.get(url) # wait for the elment to be presented ele = WebDriverWait(driver, 30).until(lambda driver: driver.execute_script('''return $('span:contains("AARONS")')[0];''')) # print the text of the element print (ele.text) ```
15,669,924
I'm trying to get tumblr "liked" posts for a user at the <http://api.tumblr.com/v2/user/likes> url. I have registered my app with tumblr and authorized the app to access the user's tumblr data, so I have `oauth_consumer_key`, `oauth_consumer_secret`, `oauth_token`, and `oauth_token secret`. However, I'm not sure what ...
2013/03/27
[ "https://Stackoverflow.com/questions/15669924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1132385/" ]
Well if you don't mind using Python I can recommend [rauth](https://github.com/litl/rauth). There isn't a Tumblr example, but there are [real world, working examples](https://github.com/litl/rauth/tree/master/examples) for both OAuth 1.0/a and OAuth 2.0. The API is intended to be simple and straight forward. I'm not su...
I sort of found an answer. I ended up using OAuth::Consumer in perl to connect to the tumblr API. It's the simplest solution I've found so far and it just works.
64,063,248
My Python version:`Python 3.8.3` `python -m pip install IPython` gives me `Successfully installed IPython-7.18.1` Still gives me the following error: ``` from IPython.display import Image /usr/bin/python3 "/home/sanyifeju/Desktop/python/ML/decision_trees.py" Traceback (most recent call last): File "/home/san...
2020/09/25
[ "https://Stackoverflow.com/questions/64063248", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1107591/" ]
I had the same issue, and the problem was that the `python` command was linked to the python2 version: ``` $ ls -l /usr/bin/python lrwxrwxrwx 1 root root 7 Apr 15 2020 /usr/bin/python -> python2* ``` The following commands fixed it for me: ``` $ sudo rm /usr/bin/python $ sudo ln -s python3 /usr/bin/python ```
Try installing- ``` python -m pip install ipython ```
13,218,362
I'm currently learning python and tried to make a little game using the pygame librabry. I use python 3.2.3 and pygame 1.9.2a with Windows Xp. Everything works fine, except one thing : if I go on another window when my game is running, it crashes and I get an error message in the console : ``` Fatal Python error: (pyg...
2012/11/04
[ "https://Stackoverflow.com/questions/13218362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1717248/" ]
I know thread is old, but I was getting the same error "Fatal Python error: (pygame parachute) Segmentation Fault" in linux when I resized a pygame window continuously for several seconds. Just in case this helps anyone else, it turned out to be caused by blitting to the window surface in one thread when I was resizing...
I don't know if you have anything after the last line that you're not putting in, but if you don't, you should replace your last line with ``` pygame.quit() sys.exit() ``` As an alternative, you could put those two lines outside of the `while` loop and keep what you have. Don't forget to `import sys`.
68,532,863
I currently have a multiple regression that generates an OLS summary based on the life expectancy and the variables that impact it, however that does not include RMSE or standard deviation. Does statsmodels have a rsme library, and is there a way to calculate standard deviation from my code? I have found a previous ex...
2021/07/26
[ "https://Stackoverflow.com/questions/68532863", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12374203/" ]
The canonical dplyr-way would be to write a custom predicate function that returns `TRUE` or `FALSE` for each column depending on whether the conditions are matched and use this function inside `across(where(predicate_function), ...)`. Below I borrow the example data from @Tob and add some variations (one column is `0...
This is what I might do but I don't know how fast it will if your data is large ``` # Create some data test_data <- data.frame(strings = c("a", "b", "c", "d", "e"), col_2 = c(1, 0, 0, 0, 1), col_3 = c( 0,1, 1, 0, 1)) # Find columns that are only 0s and 1s cols_to_convert <- names(tes...
68,532,863
I currently have a multiple regression that generates an OLS summary based on the life expectancy and the variables that impact it, however that does not include RMSE or standard deviation. Does statsmodels have a rsme library, and is there a way to calculate standard deviation from my code? I have found a previous ex...
2021/07/26
[ "https://Stackoverflow.com/questions/68532863", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12374203/" ]
This is what I might do but I don't know how fast it will if your data is large ``` # Create some data test_data <- data.frame(strings = c("a", "b", "c", "d", "e"), col_2 = c(1, 0, 0, 0, 1), col_3 = c( 0,1, 1, 0, 1)) # Find columns that are only 0s and 1s cols_to_convert <- names(tes...
Another dplyr approach to reach your goal. I used the built-in dataset `mtcars` because some columns (`vs` and `am`) of type `double` are binary (0 and 1). ``` df <- mtcars %>% mutate(across(where( ~ setequal(na.omit(.x), 0:1)), as.factor)) glimpse(df) # Rows: 32 # Columns: 11 # $ mpg <dbl> 21.0, 21.0, 22.8, 21.4...
68,532,863
I currently have a multiple regression that generates an OLS summary based on the life expectancy and the variables that impact it, however that does not include RMSE or standard deviation. Does statsmodels have a rsme library, and is there a way to calculate standard deviation from my code? I have found a previous ex...
2021/07/26
[ "https://Stackoverflow.com/questions/68532863", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12374203/" ]
The canonical dplyr-way would be to write a custom predicate function that returns `TRUE` or `FALSE` for each column depending on whether the conditions are matched and use this function inside `across(where(predicate_function), ...)`. Below I borrow the example data from @Tob and add some variations (one column is `0...
Another dplyr approach to reach your goal. I used the built-in dataset `mtcars` because some columns (`vs` and `am`) of type `double` are binary (0 and 1). ``` df <- mtcars %>% mutate(across(where( ~ setequal(na.omit(.x), 0:1)), as.factor)) glimpse(df) # Rows: 32 # Columns: 11 # $ mpg <dbl> 21.0, 21.0, 22.8, 21.4...
20,338,360
I am looking for a production database to use with python/django for web development. I've installed MySQL successfully. I believe the python connector is not working and I don't know how to make it work. Please point me in the right direction. Thanks. If I try importing `MySQLdb`: ``` import MySQLdb ``` I get the ...
2013/12/02
[ "https://Stackoverflow.com/questions/20338360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2424253/" ]
If your problem is with the `MySQLdb` module, not the MySQL server itself, you might want to consider [`PyMySQL`](https://github.com/PyMySQL/PyMySQL) instead. It's much simpler to set up. Of course it's also somewhat different. The key difference is that it's a pure Python implementation of the MySQL protocol, not a w...
I would recommend postgres.app : <http://postgresapp.com> Tried and never left My preference for the driver is <http://initd.org/psycopg/> You'll find a list of drivers at <http://wiki.postgresql.org/wiki/Python>
3,947,878
I have a appengine webapp where i need to set HTTP Location variable to redirect to another page in the same webapp. For that i need to produce a absolute link. for portability reason i cannot use directly the domain name which i am currently using. Is it possible to produce the domain name on which the webapp is host...
2010/10/16
[ "https://Stackoverflow.com/questions/3947878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/329292/" ]
I don't think I quite fully understand the need to getdomain name. But check out if redirect API provided by google app engine will do the job. <http://code.google.com/appengine/docs/python/tools/webapp/redirects.html>
this question is poorly answered. You need the domain name to generate pages like: robots.txt, sitemap.xml and many many more things which are not relative links. Ive tried using this: ``` from google.appengine.api.app_identity import get_default_version_hostname host = get_default_version_hostname() ``` but... it...
3,947,878
I have a appengine webapp where i need to set HTTP Location variable to redirect to another page in the same webapp. For that i need to produce a absolute link. for portability reason i cannot use directly the domain name which i am currently using. Is it possible to produce the domain name on which the webapp is host...
2010/10/16
[ "https://Stackoverflow.com/questions/3947878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/329292/" ]
I don't think I quite fully understand the need to getdomain name. But check out if redirect API provided by google app engine will do the job. <http://code.google.com/appengine/docs/python/tools/webapp/redirects.html>
If your application uses a [custom domain name](https://cloud.google.com/appengine/docs/python/console/using-custom-domains-and-ssl#adding_a_custom_domain_for_your_application), then *get\_default\_version\_hostname()* will return *myapp.appspot.com*, or *1.default.myapp.appspot.com* not *mydomain.com* To get the doma...
3,947,878
I have a appengine webapp where i need to set HTTP Location variable to redirect to another page in the same webapp. For that i need to produce a absolute link. for portability reason i cannot use directly the domain name which i am currently using. Is it possible to produce the domain name on which the webapp is host...
2010/10/16
[ "https://Stackoverflow.com/questions/3947878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/329292/" ]
If you're using the webapp framework, the current URL is in `self.request.url`. Various components are broken out in properties of self.request, documented [here](http://pythonpaste.org/webob/#urls).
this question is poorly answered. You need the domain name to generate pages like: robots.txt, sitemap.xml and many many more things which are not relative links. Ive tried using this: ``` from google.appengine.api.app_identity import get_default_version_hostname host = get_default_version_hostname() ``` but... it...
3,947,878
I have a appengine webapp where i need to set HTTP Location variable to redirect to another page in the same webapp. For that i need to produce a absolute link. for portability reason i cannot use directly the domain name which i am currently using. Is it possible to produce the domain name on which the webapp is host...
2010/10/16
[ "https://Stackoverflow.com/questions/3947878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/329292/" ]
If you're using the webapp framework, the current URL is in `self.request.url`. Various components are broken out in properties of self.request, documented [here](http://pythonpaste.org/webob/#urls).
If your application uses a [custom domain name](https://cloud.google.com/appengine/docs/python/console/using-custom-domains-and-ssl#adding_a_custom_domain_for_your_application), then *get\_default\_version\_hostname()* will return *myapp.appspot.com*, or *1.default.myapp.appspot.com* not *mydomain.com* To get the doma...
3,947,878
I have a appengine webapp where i need to set HTTP Location variable to redirect to another page in the same webapp. For that i need to produce a absolute link. for portability reason i cannot use directly the domain name which i am currently using. Is it possible to produce the domain name on which the webapp is host...
2010/10/16
[ "https://Stackoverflow.com/questions/3947878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/329292/" ]
this question is poorly answered. You need the domain name to generate pages like: robots.txt, sitemap.xml and many many more things which are not relative links. Ive tried using this: ``` from google.appengine.api.app_identity import get_default_version_hostname host = get_default_version_hostname() ``` but... it...
If your application uses a [custom domain name](https://cloud.google.com/appengine/docs/python/console/using-custom-domains-and-ssl#adding_a_custom_domain_for_your_application), then *get\_default\_version\_hostname()* will return *myapp.appspot.com*, or *1.default.myapp.appspot.com* not *mydomain.com* To get the doma...
71,288,828
I am trying to extract book names from oreilly media website using python beautiful soup. However I see that the book names are not in the page source html. I am using this link to see the books: [https://www.oreilly.com/search/?query=\*&extended\_publisher\_data=true&highlight=true&include\_assessments=false&includ...
2022/02/27
[ "https://Stackoverflow.com/questions/71288828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7895331/" ]
So if you investigate into network tab, when loading page, you are sending request to API [![Sent request](https://i.stack.imgur.com/kKfDY.png)](https://i.stack.imgur.com/kKfDY.png) It returns json with books. After some investigation by me, you can get your titles via ``` import json import requests response_json...
To solve this issue you need to know beautiful soup can deal with websites that use plan html. so the the websites that use JavaScript in their page beautiful soup cant's get all page data that you looking for bcz you need a browser like to load the JavaScript data in the website. and here you need to use Selenium bcz ...
63,424,301
I am trying to refresh power b.i. more frequently than current capability of gateway schedule refresh. I found this: <https://github.com/dubravcik/pbixrefresher-python> Installed and verified I have all required packages installed to run. Right now it works fine until the end - where after it refreshes a Save functio...
2020/08/15
[ "https://Stackoverflow.com/questions/63424301", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11854373/" ]
If this is your command line: ``` g++ -std=c++17 -pthread -o http_test.out http_test.cpp -lssl -lcrypto && ./http_test.out ``` Aren't you missing "-O2"? It looks like you are building without optimizations. Which will be considerably slower.
From what i know of bitmex engine, having a latency around 10ms for order execution is the best you can get, and it will be worse during high volatility periods. Check <https://bonfida.com/latency-monitor> to get an idea of latencies. On crypto world, latency are far higher than traditional hft
31,687,690
I just got a new MackBook Pro and installed Python 3.4. I ran the terminal and typed ``` python3.4 ``` I got: ``` Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. ``` I typed: ``...
2015/07/28
[ "https://Stackoverflow.com/questions/31687690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4996405/" ]
Notice the "..." prompt? That's telling you that the interactive interpreter knows you are in a block. You'll have to enter a blank line to terminate the block, before doing the final print statement. This is an artifact of running interactively -- the blank line isn't required when you type your code into a file.
You have to use space for indentation (and ";" to separate two instruction : ``` >>> counter = 5 >>> while counter > 0: counter -= 1 print("Hello") Hello Hello Hello Hello Hello >>> ```
31,687,690
I just got a new MackBook Pro and installed Python 3.4. I ran the terminal and typed ``` python3.4 ``` I got: ``` Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. ``` I typed: ``...
2015/07/28
[ "https://Stackoverflow.com/questions/31687690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4996405/" ]
Notice the "..." prompt? That's telling you that the interactive interpreter knows you are in a block. You'll have to enter a blank line to terminate the block, before doing the final print statement. This is an artifact of running interactively -- the blank line isn't required when you type your code into a file.
Because it is syntax error. ``` >>> while counter > 0: ... counter -= 1 ... print() ... print("Hello World") ``` this is how python console works - you can see that you have three dots before print('hello world') which indicates that python still expects **indendted** code that belongs to while block. You...
31,687,690
I just got a new MackBook Pro and installed Python 3.4. I ran the terminal and typed ``` python3.4 ``` I got: ``` Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. ``` I typed: ``...
2015/07/28
[ "https://Stackoverflow.com/questions/31687690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4996405/" ]
Notice the "..." prompt? That's telling you that the interactive interpreter knows you are in a block. You'll have to enter a blank line to terminate the block, before doing the final print statement. This is an artifact of running interactively -- the blank line isn't required when you type your code into a file.
This is caused by a quirk of python's interactive mode, which treats newlines specially. When you have a `...` prompt, it *must* be followed by a continuation of the preceding compound statement, rather than the beginning of a new statement, which it would in non-interactive mode. Press enter again to make the `...` p...
31,687,690
I just got a new MackBook Pro and installed Python 3.4. I ran the terminal and typed ``` python3.4 ``` I got: ``` Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. ``` I typed: ``...
2015/07/28
[ "https://Stackoverflow.com/questions/31687690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4996405/" ]
Because it is syntax error. ``` >>> while counter > 0: ... counter -= 1 ... print() ... print("Hello World") ``` this is how python console works - you can see that you have three dots before print('hello world') which indicates that python still expects **indendted** code that belongs to while block. You...
You have to use space for indentation (and ";" to separate two instruction : ``` >>> counter = 5 >>> while counter > 0: counter -= 1 print("Hello") Hello Hello Hello Hello Hello >>> ```
31,687,690
I just got a new MackBook Pro and installed Python 3.4. I ran the terminal and typed ``` python3.4 ``` I got: ``` Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. ``` I typed: ``...
2015/07/28
[ "https://Stackoverflow.com/questions/31687690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4996405/" ]
This is caused by a quirk of python's interactive mode, which treats newlines specially. When you have a `...` prompt, it *must* be followed by a continuation of the preceding compound statement, rather than the beginning of a new statement, which it would in non-interactive mode. Press enter again to make the `...` p...
You have to use space for indentation (and ";" to separate two instruction : ``` >>> counter = 5 >>> while counter > 0: counter -= 1 print("Hello") Hello Hello Hello Hello Hello >>> ```
31,687,690
I just got a new MackBook Pro and installed Python 3.4. I ran the terminal and typed ``` python3.4 ``` I got: ``` Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. ``` I typed: ``...
2015/07/28
[ "https://Stackoverflow.com/questions/31687690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4996405/" ]
Because it is syntax error. ``` >>> while counter > 0: ... counter -= 1 ... print() ... print("Hello World") ``` this is how python console works - you can see that you have three dots before print('hello world') which indicates that python still expects **indendted** code that belongs to while block. You...
This is caused by a quirk of python's interactive mode, which treats newlines specially. When you have a `...` prompt, it *must* be followed by a continuation of the preceding compound statement, rather than the beginning of a new statement, which it would in non-interactive mode. Press enter again to make the `...` p...
28,242,066
my code : ``` def isModuleBlink(modulename): f = '/tmp/'+modulename + '.blink' if(os.path.isfile(f)): with open(f) as fii: res = fii.read() print 'res',res print res is '1' if(res is '1'): print 'return true' return True return False ``` and print out : ``` res 1 False ``` ...
2015/01/30
[ "https://Stackoverflow.com/questions/28242066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3585139/" ]
`res` is `1 \n` and not `1` ... in condition i replaced `1 in res` and work ... thanks
`is` tests if things are *identical*. You want to test if two strings are equal, not necessarily that they occupy the same memory address. So you want `==`.
38,249,606
Say I have a vector of values from a tokenizing function, `tokenize()`. I know it will only have two values. I want to store the first value in `a` and the second in `b`. In Python, I would do: ```python a, b = string.split(' ') ``` I could do it as such in an ugly way: ```cpp vector<string> tokens = tokenize(strin...
2016/07/07
[ "https://Stackoverflow.com/questions/38249606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1459669/" ]
With structured bindings (definitely will be in C++17), you'd be able to write something like: ``` auto [a,b] = as_tuple<2>(tokenize(str)); ``` where `as_tuple<N>` is some to-be-declared function that converts a `vector<string>` to a `tuple<string, string, ... N times ...>`, probably throwing if the sizes don't matc...
Ideally you'd rewrite the `tokenize()` function so that it returns a pair of strings rather than a vector: ``` std::pair<std::string, std::string> tokenize(const std::string& str); ``` Or you would pass two references to empty strings to the function as parameters. ``` void tokenize(const std::string& str, std::str...
38,249,606
Say I have a vector of values from a tokenizing function, `tokenize()`. I know it will only have two values. I want to store the first value in `a` and the second in `b`. In Python, I would do: ```python a, b = string.split(' ') ``` I could do it as such in an ugly way: ```cpp vector<string> tokens = tokenize(strin...
2016/07/07
[ "https://Stackoverflow.com/questions/38249606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1459669/" ]
If you "know it will only have two values", you could write something like: ``` #include <cassert> #include <iostream> #include <string> #include <tuple> std::pair<std::string, std::string> tokenize(const std::string &text) { const auto pos(text.find(' ')); assert(pos != std::string::npos); return {text.substr...
With structured bindings (definitely will be in C++17), you'd be able to write something like: ``` auto [a,b] = as_tuple<2>(tokenize(str)); ``` where `as_tuple<N>` is some to-be-declared function that converts a `vector<string>` to a `tuple<string, string, ... N times ...>`, probably throwing if the sizes don't matc...
38,249,606
Say I have a vector of values from a tokenizing function, `tokenize()`. I know it will only have two values. I want to store the first value in `a` and the second in `b`. In Python, I would do: ```python a, b = string.split(' ') ``` I could do it as such in an ugly way: ```cpp vector<string> tokens = tokenize(strin...
2016/07/07
[ "https://Stackoverflow.com/questions/38249606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1459669/" ]
If you "know it will only have two values", you could write something like: ``` #include <cassert> #include <iostream> #include <string> #include <tuple> std::pair<std::string, std::string> tokenize(const std::string &text) { const auto pos(text.find(' ')); assert(pos != std::string::npos); return {text.substr...
Ideally you'd rewrite the `tokenize()` function so that it returns a pair of strings rather than a vector: ``` std::pair<std::string, std::string> tokenize(const std::string& str); ``` Or you would pass two references to empty strings to the function as parameters. ``` void tokenize(const std::string& str, std::str...
8,055,132
I have the script below which I'm using to send say 10 messages myself<->myself. However, I've noticed that Python really takes a while to do that. Last year I needed a system to send about 200 emails with attachments and text and I implemented it with msmtp + bash. As far as I remember it was much faster. Moving the ...
2011/11/08
[ "https://Stackoverflow.com/questions/8055132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030287/" ]
You are opening the connection to the SMTP server and then closing it for each email. It would be more efficient to keep the connection open while sending all of the emails.
The real answer here is "profile that code!". Time how long different parts of the code take so you know where most of the time is spent. That way you'll have a real answer without guesswork. Still, my guess would be that it is the calls to `smtp_serv.verify(recipient)` may be the slow ones. Reasons might be that the ...
8,055,132
I have the script below which I'm using to send say 10 messages myself<->myself. However, I've noticed that Python really takes a while to do that. Last year I needed a system to send about 200 emails with attachments and text and I implemented it with msmtp + bash. As far as I remember it was much faster. Moving the ...
2011/11/08
[ "https://Stackoverflow.com/questions/8055132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030287/" ]
In this script it takes five times more time to setup SMTP connection (5 seconds) than to send a e-mail (1 second) so it could make sense to setup a single connection and send several e-mails instead of creating the connection each time: ``` #!/usr/bin/env python3 import smtplib from contextlib import contextmanag...
You are opening the connection to the SMTP server and then closing it for each email. It would be more efficient to keep the connection open while sending all of the emails.
8,055,132
I have the script below which I'm using to send say 10 messages myself<->myself. However, I've noticed that Python really takes a while to do that. Last year I needed a system to send about 200 emails with attachments and text and I implemented it with msmtp + bash. As far as I remember it was much faster. Moving the ...
2011/11/08
[ "https://Stackoverflow.com/questions/8055132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030287/" ]
In this script it takes five times more time to setup SMTP connection (5 seconds) than to send a e-mail (1 second) so it could make sense to setup a single connection and send several e-mails instead of creating the connection each time: ``` #!/usr/bin/env python3 import smtplib from contextlib import contextmanag...
The real answer here is "profile that code!". Time how long different parts of the code take so you know where most of the time is spent. That way you'll have a real answer without guesswork. Still, my guess would be that it is the calls to `smtp_serv.verify(recipient)` may be the slow ones. Reasons might be that the ...
8,055,132
I have the script below which I'm using to send say 10 messages myself<->myself. However, I've noticed that Python really takes a while to do that. Last year I needed a system to send about 200 emails with attachments and text and I implemented it with msmtp + bash. As far as I remember it was much faster. Moving the ...
2011/11/08
[ "https://Stackoverflow.com/questions/8055132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030287/" ]
Maybe this comes very late, but I think it is relevant for the matter. I had the same issue recently and realized, by searching around, that the call to connect the SMTP server may be very time consuming due to issues with domain name resolution, since the SMTP server performs a reverse lookup to verify the connecting ...
The real answer here is "profile that code!". Time how long different parts of the code take so you know where most of the time is spent. That way you'll have a real answer without guesswork. Still, my guess would be that it is the calls to `smtp_serv.verify(recipient)` may be the slow ones. Reasons might be that the ...
8,055,132
I have the script below which I'm using to send say 10 messages myself<->myself. However, I've noticed that Python really takes a while to do that. Last year I needed a system to send about 200 emails with attachments and text and I implemented it with msmtp + bash. As far as I remember it was much faster. Moving the ...
2011/11/08
[ "https://Stackoverflow.com/questions/8055132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030287/" ]
In this script it takes five times more time to setup SMTP connection (5 seconds) than to send a e-mail (1 second) so it could make sense to setup a single connection and send several e-mails instead of creating the connection each time: ``` #!/usr/bin/env python3 import smtplib from contextlib import contextmanag...
Maybe this comes very late, but I think it is relevant for the matter. I had the same issue recently and realized, by searching around, that the call to connect the SMTP server may be very time consuming due to issues with domain name resolution, since the SMTP server performs a reverse lookup to verify the connecting ...
34,162,320
I want to execute bash command ``` '/bin/echo </verbosegc> >> /tmp/jruby.log' ``` in python using Popen. The code does not raise any exception, but none change is made on the jruby.log after execution. The python code is shown below. ``` >>> command='/bin/echo </verbosegc> >> '+fullpath >>> command '/bin/echo </v...
2015/12/08
[ "https://Stackoverflow.com/questions/34162320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/910118/" ]
The first argument to `subprocess.Popen` is the array `['/bin/echo', '</verbosegc>', '>>', '/tmp/jruby.log']`. When the first argument to `subprocess.Popen` is an array, it does not launch a shell to run the command, and the shell is what's responsible for interpreting `>> /tmp/jruby.log` to mean "write output to jruby...
Have you tried without splitting the command `and using shell=True`? My usual format is: ``` process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) output = process.stdout.read() # or .readlines() ```
34,162,320
I want to execute bash command ``` '/bin/echo </verbosegc> >> /tmp/jruby.log' ``` in python using Popen. The code does not raise any exception, but none change is made on the jruby.log after execution. The python code is shown below. ``` >>> command='/bin/echo </verbosegc> >> '+fullpath >>> command '/bin/echo </v...
2015/12/08
[ "https://Stackoverflow.com/questions/34162320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/910118/" ]
Consider the following: ``` command = [ 'printf "%s\n" "$1" >>"$2"', # shell script to execute '', # $0 in shell '</verbosegc>', # $1 '/tmp/jruby.log' ] # $2 subprocess.Popen(command, shell=True) ``` The first argument is a shell...
Have you tried without splitting the command `and using shell=True`? My usual format is: ``` process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) output = process.stdout.read() # or .readlines() ```
34,162,320
I want to execute bash command ``` '/bin/echo </verbosegc> >> /tmp/jruby.log' ``` in python using Popen. The code does not raise any exception, but none change is made on the jruby.log after execution. The python code is shown below. ``` >>> command='/bin/echo </verbosegc> >> '+fullpath >>> command '/bin/echo </v...
2015/12/08
[ "https://Stackoverflow.com/questions/34162320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/910118/" ]
Just use pass file object if you want to append the output to a file, you cannot redirect to a file unless you set `shell=True`: ``` command = ['/bin/echo', '</verbosegc>'] with open('/tmp/jruby.log',"a") as f: subprocess.check_call(command, stdout=f,stderr=subprocess.STDOUT) ```
Have you tried without splitting the command `and using shell=True`? My usual format is: ``` process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) output = process.stdout.read() # or .readlines() ```
34,162,320
I want to execute bash command ``` '/bin/echo </verbosegc> >> /tmp/jruby.log' ``` in python using Popen. The code does not raise any exception, but none change is made on the jruby.log after execution. The python code is shown below. ``` >>> command='/bin/echo </verbosegc> >> '+fullpath >>> command '/bin/echo </v...
2015/12/08
[ "https://Stackoverflow.com/questions/34162320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/910118/" ]
The first argument to `subprocess.Popen` is the array `['/bin/echo', '</verbosegc>', '>>', '/tmp/jruby.log']`. When the first argument to `subprocess.Popen` is an array, it does not launch a shell to run the command, and the shell is what's responsible for interpreting `>> /tmp/jruby.log` to mean "write output to jruby...
Consider the following: ``` command = [ 'printf "%s\n" "$1" >>"$2"', # shell script to execute '', # $0 in shell '</verbosegc>', # $1 '/tmp/jruby.log' ] # $2 subprocess.Popen(command, shell=True) ``` The first argument is a shell...
34,162,320
I want to execute bash command ``` '/bin/echo </verbosegc> >> /tmp/jruby.log' ``` in python using Popen. The code does not raise any exception, but none change is made on the jruby.log after execution. The python code is shown below. ``` >>> command='/bin/echo </verbosegc> >> '+fullpath >>> command '/bin/echo </v...
2015/12/08
[ "https://Stackoverflow.com/questions/34162320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/910118/" ]
Just use pass file object if you want to append the output to a file, you cannot redirect to a file unless you set `shell=True`: ``` command = ['/bin/echo', '</verbosegc>'] with open('/tmp/jruby.log',"a") as f: subprocess.check_call(command, stdout=f,stderr=subprocess.STDOUT) ```
Consider the following: ``` command = [ 'printf "%s\n" "$1" >>"$2"', # shell script to execute '', # $0 in shell '</verbosegc>', # $1 '/tmp/jruby.log' ] # $2 subprocess.Popen(command, shell=True) ``` The first argument is a shell...
46,668,481
I'm trying to use PyQt\_Fit. I installed it from pip install pyqt\_fit but when I import it does not work and show me this message: ``` ----------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-8-36ec621967a7> in <modu...
2017/10/10
[ "https://Stackoverflow.com/questions/46668481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8752769/" ]
I faced the same problem with you. when I install the pyqt\_fit package successfully by ``` sudo pip install git+https://github.com/Multiplicom/pyqt-fit.git ``` It will install the path.py (The last version) and pyqt\_fit at the same time. Then When I import the package, I faced the follow error ``` import pyqt_fi...
This seems to be happening for quite some time. Check this recent issue report [on the repo](https://github.com/sergeyfarin/pyqt-fit/issues/5). I've installed the package and tested myself and I got the same problem. Checked the solution provided on the possible duplicate and seems to have fixed the problem. You migh...
46,668,481
I'm trying to use PyQt\_Fit. I installed it from pip install pyqt\_fit but when I import it does not work and show me this message: ``` ----------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-8-36ec621967a7> in <modu...
2017/10/10
[ "https://Stackoverflow.com/questions/46668481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8752769/" ]
Although people are suggesting `path.py==7.7.1`, it worked with `path.py=7.1` for me: ``` sudo pip uninstall -y path.py sudo pip install -I path.py==7.1 ``` I'm also using Ubuntu 16.04.
This seems to be happening for quite some time. Check this recent issue report [on the repo](https://github.com/sergeyfarin/pyqt-fit/issues/5). I've installed the package and tested myself and I got the same problem. Checked the solution provided on the possible duplicate and seems to have fixed the problem. You migh...
72,179,492
Recently, I updated to Ubuntu 22. I am using python 3.10. After installing matplotlib and other required libraries for python, I am trying to plot some graphs. Everytime I am facing this error while running my code. I followed all the solutions given in stackoverflow or Google but no luck. This is the error I am get...
2022/05/10
[ "https://Stackoverflow.com/questions/72179492", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16780162/" ]
``` md$Children[which(x >= 8 & y < 60)] = NA ```
@AbdurRohman's answer is good. You could use ```r md <- within(md, Children[Children >= 8 & Age <60] <- NA ) ``` for slightly clearer code. (You should definitely tell your instructor you got help on Stack Overflow.)
9,794,616
I'm using the following code which will generate a wav file which contains a tone at 440 Hz lasting for 2 seconds. ``` from scipy.io.wavfile import write from numpy import linspace,sin,pi,int16 def note(freq, len, amp=1, rate=44100): t = linspace(0,len,len*rate) data = sin(2*pi*freq*t)*amp return data.astype(int1...
2012/03/20
[ "https://Stackoverflow.com/questions/9794616", "https://Stackoverflow.com", "https://Stackoverflow.com/users/840973/" ]
You can do this using numpy.concatenate, (as already posted). You need to specify the concatenation axis also. Using very low rate to illustrate: ``` from scipy.io.wavfile import write from numpy import linspace,sin,pi,int16,concatenate def note(freq, len, amp=1, rate=5): t = linspace(0,len,len*rate) data = sin(2*p...
`numpy.linspace` creates a numpy array. To concatenate the tones, you'd want to concatenate the corresponding arrays. For this, a bit of Googling indicates that Numpy provides the helpfully named [`numpy.concatenate` function](http://docs.scipy.org/doc/numpy/reference/generated/numpy.concatenate.html).
5,151,898
I realized there is a memory leak in one python script. Which occupied around 25MB first, and after 15 days it is more than 500 MB. I followed many different ways, and not able to get into the root of the problem as am a python newbie... Finally, I got this following ``` objgraph.show_most_common_types(limit=20) t...
2011/03/01
[ "https://Stackoverflow.com/questions/5151898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/379997/" ]
Am I reading correctly that the same script is running for 15 days non-stop? For such long-running processes periodic restart is a good practice and it's much easier to do than eliminating all memory leaks. *Update*: Look at [this answer](https://stackoverflow.com/questions/1641231/python-working-around-memory-leaks/...
My first thought is, probably you are creating new objects in you script and accumulating them in some sort of global list. It is usually easier to go over your script and make sure that you are not generating any persistent data than debugging the garbage. I think the utility you are using, objgraph, also allows you t...
10,928,313
Is anyone familiar with DRAKON? I quite like the idea of the DRAKON visual editor and have been playing with it using Python -- more info: <http://drakon-editor.sourceforge.net/python/python.html> The only thing I've had a problem with so far is python's try: except: exceptions. The only way I've attempted it is to u...
2012/06/07
[ "https://Stackoverflow.com/questions/10928313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/507286/" ]
You could put the whole "try: except:" construct inside one "Action" icon like this: ![Catching exceptions in DRAKON-Python](https://i.stack.imgur.com/sY7tP.png) Both spaces and tabs can be used for indentation inside an icon.
There are limitation exist in Drakon since it is a code generator, but what you can do is to re-factor the code as much as possible and stuff it inside action block: ``` try: function_1() function_2() except: function_3() ``` Drakon works best if you follow suggested rules(skewer,happy route,branching etc)...
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
This could be because your CSV file has embedded single or double quotes. If your CSV file is tab-delimited try opening it as: ``` c = csv.reader(f, delimiter='\t', quoting=csv.QUOTE_NONE) ```
You can use the `error_bad_lines` option of `pd.read_csv` to skip these lines. ```py import pandas as pd data_df = pd.read_csv('data.csv', error_bad_lines=False) ``` This works since the "bad lines" as defined in pandas include lines that one of their fields exceed the csv limit. Be careful that this solution is v...
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
This could be because your CSV file has embedded single or double quotes. If your CSV file is tab-delimited try opening it as: ``` c = csv.reader(f, delimiter='\t', quoting=csv.QUOTE_NONE) ```
I just had this happen to me on a 'plain' CSV file. Some people might call it an invalid formatted file. No escape characters, no double quotes and delimiter was a semicolon. A sample line from this file would look like this: > > First cell; Second " Cell with one double quote and leading > space;'Partially quoted'...
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
Below is to check the current limit ``` csv.field_size_limit() ``` Out[20]: 131072 Below is to increase the limit. Add it to the code ``` csv.field_size_limit(100000000) ``` Try checking the limit again ``` csv.field_size_limit() ``` Out[22]: 100000000 Now you won't get the error "\_csv.Error: field larger t...
Sometimes, a row contain double quote column. When csv reader try read this row, not understood end of column and fire this raise. Solution is below: ``` reader = csv.reader(cf, quoting=csv.QUOTE_MINIMAL) ```
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
The csv file might contain very huge fields, therefore increase the `field_size_limit`: ``` import sys import csv csv.field_size_limit(sys.maxsize) ``` `sys.maxsize` works for Python 2.x and 3.x. `sys.maxint` would only work with Python 2.x ([SO: what-is-sys-maxint-in-python-3](https://stackoverflow.com/questions/1...
I just had this happen to me on a 'plain' CSV file. Some people might call it an invalid formatted file. No escape characters, no double quotes and delimiter was a semicolon. A sample line from this file would look like this: > > First cell; Second " Cell with one double quote and leading > space;'Partially quoted'...
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
Below is to check the current limit ``` csv.field_size_limit() ``` Out[20]: 131072 Below is to increase the limit. Add it to the code ``` csv.field_size_limit(100000000) ``` Try checking the limit again ``` csv.field_size_limit() ``` Out[22]: 100000000 Now you won't get the error "\_csv.Error: field larger t...
You can use the `error_bad_lines` option of `pd.read_csv` to skip these lines. ```py import pandas as pd data_df = pd.read_csv('data.csv', error_bad_lines=False) ``` This works since the "bad lines" as defined in pandas include lines that one of their fields exceed the csv limit. Be careful that this solution is v...
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
Below is to check the current limit ``` csv.field_size_limit() ``` Out[20]: 131072 Below is to increase the limit. Add it to the code ``` csv.field_size_limit(100000000) ``` Try checking the limit again ``` csv.field_size_limit() ``` Out[22]: 100000000 Now you won't get the error "\_csv.Error: field larger t...
Find the cqlshrc file usually placed in .cassandra directory. In that file append, ``` [csv] field_size_limit = 1000000000 ```
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
The csv file might contain very huge fields, therefore increase the `field_size_limit`: ``` import sys import csv csv.field_size_limit(sys.maxsize) ``` `sys.maxsize` works for Python 2.x and 3.x. `sys.maxint` would only work with Python 2.x ([SO: what-is-sys-maxint-in-python-3](https://stackoverflow.com/questions/1...
*.csv* field sizes are controlled via [[Python.Docs]: csv.field\_size\_limit([new\_limit])](https://docs.python.org/library/csv.html#csv.field_size_limit) (**emphasis** is mine): > > Returns the current maximum field size allowed by the parser. **If *new\_limit* is given, this becomes the new limit**. > > > It is...
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
Sometimes, a row contain double quote column. When csv reader try read this row, not understood end of column and fire this raise. Solution is below: ``` reader = csv.reader(cf, quoting=csv.QUOTE_MINIMAL) ```
Find the cqlshrc file usually placed in .cassandra directory. In that file append, ``` [csv] field_size_limit = 1000000000 ```
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
The csv file might contain very huge fields, therefore increase the `field_size_limit`: ``` import sys import csv csv.field_size_limit(sys.maxsize) ``` `sys.maxsize` works for Python 2.x and 3.x. `sys.maxint` would only work with Python 2.x ([SO: what-is-sys-maxint-in-python-3](https://stackoverflow.com/questions/1...
Sometimes, a row contain double quote column. When csv reader try read this row, not understood end of column and fire this raise. Solution is below: ``` reader = csv.reader(cf, quoting=csv.QUOTE_MINIMAL) ```
15,063,936
I have a script reading in a csv file with very huge fields: ``` # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) ``` However, this throws the followin...
2013/02/25
[ "https://Stackoverflow.com/questions/15063936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251007/" ]
*.csv* field sizes are controlled via [[Python.Docs]: csv.field\_size\_limit([new\_limit])](https://docs.python.org/library/csv.html#csv.field_size_limit) (**emphasis** is mine): > > Returns the current maximum field size allowed by the parser. **If *new\_limit* is given, this becomes the new limit**. > > > It is...
You can use the `error_bad_lines` option of `pd.read_csv` to skip these lines. ```py import pandas as pd data_df = pd.read_csv('data.csv', error_bad_lines=False) ``` This works since the "bad lines" as defined in pandas include lines that one of their fields exceed the csv limit. Be careful that this solution is v...
48,206,553
I am trying to make a view that i can use in multiple apps with different redirect urls: Parent function: ``` def create_order(request, redirect_url): data = dict() if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): form.save() return redire...
2018/01/11
[ "https://Stackoverflow.com/questions/48206553", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7161215/" ]
``` url(r'^orders/create/', views.create_order, name='create_order') ``` This clearly is not going to work, since `create_order` requires `redirect_url` but there is no `redirect_url` kwarg in the regex `r'^orders/create/'`. Perhaps you want to use the `admin_order_document` view here instead: ``` url(r'^orders/cre...
If you didn't changed the regular url ``` urlpatterns = [ url(r'^admin/', admin_site.urls), ... ] ``` of your admin site you need to call your function like that: ``` @login_required() def admin_order_document(request): redirect_url = 'admin:order_waiting_list' return create_order(request, redirect...
35,438,785
I have a list of numbers and I want to make rows and columns out of the list. I can brute force it and do the following below in Python 2.7. ``` l = [1,2,3,4,5,6,7,8,9] r1 = [l[0], l[1], l[2]] r2 = [l[3], l[4], l[5]] r3 = [l[6], l[7], l[8]] c1 = [l[0], l[3], l[6]] ``` But I can't seem to create a function in py...
2016/02/16
[ "https://Stackoverflow.com/questions/35438785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5936229/" ]
Your error is a misunderstanding in [how Python passes arguments](http://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k-dick/). `r` in the function `make_row` is just a name. When you assign into it, it simply points that name to something new, in the context of your function, lea...
Your function `make_row` works as far as I can tell (I have not tested it), but you need to `return r`.
35,438,785
I have a list of numbers and I want to make rows and columns out of the list. I can brute force it and do the following below in Python 2.7. ``` l = [1,2,3,4,5,6,7,8,9] r1 = [l[0], l[1], l[2]] r2 = [l[3], l[4], l[5]] r3 = [l[6], l[7], l[8]] c1 = [l[0], l[3], l[6]] ``` But I can't seem to create a function in py...
2016/02/16
[ "https://Stackoverflow.com/questions/35438785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5936229/" ]
Your error is a misunderstanding in [how Python passes arguments](http://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k-dick/). `r` in the function `make_row` is just a name. When you assign into it, it simply points that name to something new, in the context of your function, lea...
OK I think i figured out my own question. The code should look like this. ``` def make_row(li, arg1, arg2, arg3): r = [li[arg1], li[arg2], li[arg3]] return r row1 = make_row(li, 0, 1, 2) ```
35,438,785
I have a list of numbers and I want to make rows and columns out of the list. I can brute force it and do the following below in Python 2.7. ``` l = [1,2,3,4,5,6,7,8,9] r1 = [l[0], l[1], l[2]] r2 = [l[3], l[4], l[5]] r3 = [l[6], l[7], l[8]] c1 = [l[0], l[3], l[6]] ``` But I can't seem to create a function in py...
2016/02/16
[ "https://Stackoverflow.com/questions/35438785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5936229/" ]
OK I think i figured out my own question. The code should look like this. ``` def make_row(li, arg1, arg2, arg3): r = [li[arg1], li[arg2], li[arg3]] return r row1 = make_row(li, 0, 1, 2) ```
Your function `make_row` works as far as I can tell (I have not tested it), but you need to `return r`.
42,230,691
For a beginner in Tkinter, and just average in Python, it's hard to find proper stuff on tkinter. Here is the problem I met (and begin to solve). I think Problem came from python version. I'm trying to do a GUI, in OOP, and I got difficulty in combining different classes. Let say I have a "small box" (for example, a ...
2017/02/14
[ "https://Stackoverflow.com/questions/42230691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6721930/" ]
The tutorial you are using has an incorrect example. The `Tk` class doesn't have a parent. Also, you must only create a single instance of `Tk` (or subclass of `Tk`). Tkinter widgets exist in a tree-like hierarchy with a single root. This root widget is `Tk()`. You cannot have more than one root.
The code looks quite similar at this one : [Best way to structure a tkinter application](https://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application) But there is one slight difference, we're not working on Frame here. And the error asks for a problem in screenName, etc. which, intuitively...
45,733,399
I have a Javascript file `Commodity.js` like this: ``` commodityInfo = [ ["GLASS ITEM", 1.0, 1.0, ], ["HOUSEHOLD GOODS", 3.0, 2.0, ], ["FROZEN PRODUCTS", 1.0, 3.0, ], ["BEDDING", 1.0, 4.0, ], ["PERFUME", 1.0, 5.0, ], ["HARDWARE", 5.0, 6.0, ], ["CURTAIN", 1.0, 7.0, ], ["CLOTHING", 24.0, 8.0, ], ["ELECTRICAL IT...
2017/08/17
[ "https://Stackoverflow.com/questions/45733399", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6624726/" ]
The following code may not be the most efficient, but it works for your case. What I'm doing here: turn the string (the content of the file) into valid JSON and then load the JSON string into a Python variable. Note: It would be easier if the content of your JS file was already valid JSON! ``` import re import json ...
You can use `for` loops to achieve that. Something like this would work: ``` for commodity in commodityInfo: commodity[0] # the first element (e.g: GLASS ITEM) commodity[1] # the second element (e.g: 1.0) print(commodity[1] + commodity[2]) #calculate two values ``` You can learn more about `for` loops [...
20,554,040
I'm new with Django and I follow a tuto. The problem is that the tuto uses Sqlite but I want to use MySql server instead. I changed the parameters following documentation but I have the following error when I try to run the server. I already found some resolve but it didn't work... For your information, I installed My...
2013/12/12
[ "https://Stackoverflow.com/questions/20554040", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2904080/" ]
Your problem is most likely related to buffering in your system, not anything intrinsically wrong with your line of code. I was able to create a test scenario where I could reproduce it - then make it go away. I hope it will work for you too. Here is my test scenario. First I write a short script that writes the time ...
Consider how `uniq -c` is working. In order to print the count, it needs to read all the unique lines and only once a line that is different from the previous one, it can print the line and number of occurences. That's just how the algorithm fundamentally works and there is no way around it. You can test this by run...
20,554,040
I'm new with Django and I follow a tuto. The problem is that the tuto uses Sqlite but I want to use MySql server instead. I changed the parameters following documentation but I have the following error when I try to run the server. I already found some resolve but it didn't work... For your information, I installed My...
2013/12/12
[ "https://Stackoverflow.com/questions/20554040", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2904080/" ]
You may try `logtop`, (`apt-get install logtop`): Usage: ``` tail -F /var/logs/request.log | [cut the date-time] | logtop ``` Example: ``` $ tail -f /var/log/varnish/varnishncsa.log | awk '{print $4}' | logtop 5585 elements in 10 seconds (558.50 elements/s) 1 690 69.00/s [28/Mar/2015:23:13:48 2 676 67.60/...
Consider how `uniq -c` is working. In order to print the count, it needs to read all the unique lines and only once a line that is different from the previous one, it can print the line and number of occurences. That's just how the algorithm fundamentally works and there is no way around it. You can test this by run...
20,554,040
I'm new with Django and I follow a tuto. The problem is that the tuto uses Sqlite but I want to use MySql server instead. I changed the parameters following documentation but I have the following error when I try to run the server. I already found some resolve but it didn't work... For your information, I installed My...
2013/12/12
[ "https://Stackoverflow.com/questions/20554040", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2904080/" ]
Your problem is most likely related to buffering in your system, not anything intrinsically wrong with your line of code. I was able to create a test scenario where I could reproduce it - then make it go away. I hope it will work for you too. Here is my test scenario. First I write a short script that writes the time ...
You may try `logtop`, (`apt-get install logtop`): Usage: ``` tail -F /var/logs/request.log | [cut the date-time] | logtop ``` Example: ``` $ tail -f /var/log/varnish/varnishncsa.log | awk '{print $4}' | logtop 5585 elements in 10 seconds (558.50 elements/s) 1 690 69.00/s [28/Mar/2015:23:13:48 2 676 67.60/...
6,929,981
I'm trying to build a regex that joins numbers in a string when they have spaces between them, ex: ``` $string = "I want to go home 8890 7463 and then go to 58639 6312 the cinema" ``` The regex should output: ``` "I want to go home 88907463 and then go to 586396312 the cinema" ``` The regex can be either in pytho...
2011/08/03
[ "https://Stackoverflow.com/questions/6929981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/797495/" ]
Use a look-ahead to see if the next block is a set of numbers and remove the trailing space. That way, it works for any number of sets (which I suspected you might want): ``` $string = "I want to go home 8890 7463 41234 and then go to 58639 6312 the cinema"; $newstring = preg_replace("/\b(\d+)\s+(?=\d+\b)/", "$1", $s...
Python: ``` import re text = 'abc 123 456 789 xyz' text = re.sub(r'(\d+)\s+(?=\d)', r'\1', text) # abc 123456789 xyz ``` This works for any number of consecutive number groups, with any amount of spacing in-between.
71,583,214
In GitBook, the title shows up while mousing over them by default. [![GitBook title hover](https://i.stack.imgur.com/nXE8q.png)](https://i.stack.imgur.com/nXE8q.png) I wanna show up the title. I inspect the elements, ```html <div class="book-header" role="navigation"> <!-- Title --> <h1> <i class="fa...
2022/03/23
[ "https://Stackoverflow.com/questions/71583214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3067748/" ]
Because .book-header h1 opacity is 0. Try add this to your css. ``` .book-header h1 { opacity:1!important; } ```
Try this! More about `color: inherit` [here](https://www.w3schools.com/cssref/css_inherit.asp). You can use other property like `z-index`, `opacity` and `position` if it doesn't work too. Thanks :) ```css .book-header h1 a, .book-header h1 a:hover { display: block !important; color: #000 !important; text-d...
46,908,231
I'm a noobie, learning to code and i stumbled upon an incorrect output while practicing a code in python, please help me with this. I tried my best to find the problem in the code but i could not find it. Code: ``` def compare(x,y): if x>y: return 1 elif x==y: return 0 else: return...
2017/10/24
[ "https://Stackoverflow.com/questions/46908231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8818971/" ]
`raw_input` returns a string always. so you have to convert the input values into numbers. ``` i=raw_input("enter x\n") j=raw_input("enter y\n") print compare(i,j) ``` should be ``` i=int(raw_input("enter x\n")) j=int(raw_input("enter y\n")) print compare(i,j) ```
Your issue is that `raw_input()` returns a string, not an integer. Therefore, what your function is actually doing is checking "10" > "5", which is `False`, therefore it falls through your `if` block and reaches the `else` clause. To fix this, you'll need to cast your input strings to integers by wrapping the values ...
46,908,231
I'm a noobie, learning to code and i stumbled upon an incorrect output while practicing a code in python, please help me with this. I tried my best to find the problem in the code but i could not find it. Code: ``` def compare(x,y): if x>y: return 1 elif x==y: return 0 else: return...
2017/10/24
[ "https://Stackoverflow.com/questions/46908231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8818971/" ]
`raw_input` returns a string always. so you have to convert the input values into numbers. ``` i=raw_input("enter x\n") j=raw_input("enter y\n") print compare(i,j) ``` should be ``` i=int(raw_input("enter x\n")) j=int(raw_input("enter y\n")) print compare(i,j) ```
Use the inbuilt cmp builtin function. ``` >>> help(cmp) Help on built-in function cmp in module __builtin__: cmp(...) cmp(x, y) -> integer Return negative if x<y, zero if x==y, positive if x>y. ``` So your function will look like this. ``` >>> def compare(x,y): ... return cmp(x,y) ... >>> ``` Then ge...
66,385,439
I'm working on a project where I need to convert a set of data rows from database into `list of OrderedDict` for other purpose and use this `list of OrderedDict` to convert into a `nested JSON` format in `python`. I'm starting to learn python. I was able convert the query response from database which is a `list of list...
2021/02/26
[ "https://Stackoverflow.com/questions/66385439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2699684/" ]
I was able to write a python code to get the format as I needed using simple looping with a couple of changes in the output like the fields SessionID, Num\_Pax and Channel is taken outside then the OUTBOUND field and fields within are generated. Instead of OrderedDict, I used a list of lists as input which I convert i...
Assuming that you stored the dictionary to some variable `foo`, you can do: ```py import json json.dumps(foo) ``` And be careful, you added extra bracket in the 4th element `OUTBOUND` list
67,055,004
My Azure devops page will look like : [![enter image description here](https://i.stack.imgur.com/YBdJx.png)](https://i.stack.imgur.com/YBdJx.png) I have 4 pandas dataframes. I need to create 4 sub pages in Azure devops wiki from each dataframe. Say, Sub1 from first dataframe, Sub2 from second dataframe and so on. My...
2021/04/12
[ "https://Stackoverflow.com/questions/67055004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11049287/" ]
use value() method ``` $user->image()->value('image'); ``` From [Eloquent documentation](https://laravel.com/docs/8.x/queries#retrieving-a-single-row-column-from-a-table) > > If you don't need an entire row, you may extract a single value from a record using the value method. This method will return the value of t...
You can create another function inside your model and access the previous method like ``` public function image() { return $this->hasOne(UserImages::class, 'user_id', 'id')->latest(); } public function avatar() { return $this->image->image ?: null; //OR return $this->image->image ?? null; //OR return !is_...
67,055,004
My Azure devops page will look like : [![enter image description here](https://i.stack.imgur.com/YBdJx.png)](https://i.stack.imgur.com/YBdJx.png) I have 4 pandas dataframes. I need to create 4 sub pages in Azure devops wiki from each dataframe. Say, Sub1 from first dataframe, Sub2 from second dataframe and so on. My...
2021/04/12
[ "https://Stackoverflow.com/questions/67055004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11049287/" ]
use value() method ``` $user->image()->value('image'); ``` From [Eloquent documentation](https://laravel.com/docs/8.x/queries#retrieving-a-single-row-column-from-a-table) > > If you don't need an entire row, you may extract a single value from a record using the value method. This method will return the value of t...
You could use the magic Laravel provided: ``` $user->image->pluck('profile_image'); ``` Documentation: <https://laravel.com/docs/8.x/collections#method-pluck>
30,114,579
I am running ubuntu 12.04 and running programs through the terminal. I have a file that compiles and runs without any issues when I am in the current directory. Example below, ``` david@block-ubuntu:~/Documents/BudgetAutomation/BillList$ pwd /home/david/Documents/BudgetAutomation/BillList david@block-ubunt...
2015/05/08
[ "https://Stackoverflow.com/questions/30114579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4362951/" ]
Your problem starts in line 5: ``` arr = glob.glob('./*.txt') ``` You are telling glob to look in the local directory for all .txt files. Since you are one directory up you do not have these files. You are getting a ValueError because the line variable is empty. As it is written you will need to run it from that ...
You don't need to create that range object to iterate over the glob result. You can just do it like this: ``` for file_path in arr: with open(file_path) as text_file: #...code below... ``` The reason of why that exception is raised, I guess, is there exist text files contain content not conforming with y...