python-3.x

Django doesn't email reporting an internal server error (HTTP status code 500)

别说谁变了你拦得住时间么 提交于 2021-02-08 20:53:48
问题 I could send mail using the following code E:\Python\django-test\LYYDownloaderServer>python manage.py shell Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (In tel)] on win32 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from django.core.mail import send_mail >>> >>> send_mail( ... 'Subject here', ... 'Here is the message.', ... 'redstone-cold@163.com', ... ['2281570025@qq.com'], ... fail_silently=False, ... ) 1 >>

Received “UnboundLocalError: local variable 'e' referenced before assignment” when the variable was initialized

早过忘川 提交于 2021-02-08 20:52:50
问题 [Community edit to give reproducible example:] def main(): e = None print(locals()) while not e: try: raise Exception except Exception as e: pass main() produces ~/coding$ python3.3 quiz2.py {'e': None} Traceback (most recent call last): File "quiz2.py", line 11, in <module> main() File "quiz2.py", line 5, in main while not e: UnboundLocalError: local variable 'e' referenced before assignment [EDITED] to include a reproducible code I am trying to run a while-loop, and the condition I use is

How can I find all prime numbers in a given range?

吃可爱长大的小学妹 提交于 2021-02-08 19:41:26
问题 def all primes(start,end): list_primes = [] for i in range(start,end): for a in range(2,i): if i % a == 0: list_primes.append(i) return list_primes For some reason it returns everything but the primes. Its probably some silly mistake. Can anyone help? 回答1: Try this (uses Sieve of Eratosthenes): def all_primes(start, end): return list(sorted(set(range(start,end+1)).difference(set((p * f) for p in range(2, int(end ** 0.5) + 2) for f in range(2, (end/p) + 1))))) 回答2: For getting prime numbers,

Format a LaTeX math string in Python 3

亡梦爱人 提交于 2021-02-08 17:12:15
问题 I see it is possible to use the format method on a LaTeX string in python by using a double curly bracket as shown here. For instance: In[1]: 'f_{{{0}}}'.format('in') Out[1]: 'f_{in}' But how can I use the format method in a math LaTeX string? (particularly for subscripts) For example, with: In[2]: r'$f_{in,{{0}}}$'.format('a') I would expect: Out[2]: '$f_{in,a}$' But I get a ValueError: unexpected '{' in field name 回答1: The correct statement for In[2] should be: r'$f_{{in,{0}}}$'.format('a')

Format a LaTeX math string in Python 3

无人久伴 提交于 2021-02-08 17:10:20
问题 I see it is possible to use the format method on a LaTeX string in python by using a double curly bracket as shown here. For instance: In[1]: 'f_{{{0}}}'.format('in') Out[1]: 'f_{in}' But how can I use the format method in a math LaTeX string? (particularly for subscripts) For example, with: In[2]: r'$f_{in,{{0}}}$'.format('a') I would expect: Out[2]: '$f_{in,a}$' But I get a ValueError: unexpected '{' in field name 回答1: The correct statement for In[2] should be: r'$f_{{in,{0}}}$'.format('a')

Format a LaTeX math string in Python 3

妖精的绣舞 提交于 2021-02-08 17:00:53
问题 I see it is possible to use the format method on a LaTeX string in python by using a double curly bracket as shown here. For instance: In[1]: 'f_{{{0}}}'.format('in') Out[1]: 'f_{in}' But how can I use the format method in a math LaTeX string? (particularly for subscripts) For example, with: In[2]: r'$f_{in,{{0}}}$'.format('a') I would expect: Out[2]: '$f_{in,a}$' But I get a ValueError: unexpected '{' in field name 回答1: The correct statement for In[2] should be: r'$f_{{in,{0}}}$'.format('a')

Dealing with module name collision

南笙酒味 提交于 2021-02-08 15:18:38
问题 Occasionally, module name collisions happen between the application and an internal file in a third-party package. For example, a file named profile.py in the current folder will cause jupyter notebook to crash as it attempts to import it instead of its own profile.py . What's a good way to avoid this problem, from the perspective of the package user? (Or is this something that the package developer should somehow prevent?) Note: while a similar problem occurs due to a collision between

Preventing a multiplication expression evaluating in Sympy

我是研究僧i 提交于 2021-02-08 15:07:51
问题 I am generating an expression with two fractions, and want to pretty print as a whole expression with LaTeX, to then put on a worksheet. E.g. in the form: (5/7) * (3/4). However, when I do the following: fract1 = sympy.sympify(Fraction(5,7)) fract2 = sympy.sympify(Fraction(3,4)) expression = sympy.Mul(fract1,fract2,evaluate=False) It returns 5*3/(7*4) Clearly it is combining the fraction but not actually evaluating, but I want to be able to produce it in a format suitable as a question for a

Continued Fractions Python [closed]

倾然丶 夕夏残阳落幕 提交于 2021-02-08 15:01:58
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . Improve this question I am new to Python and was asked to create a program that would take an input as a non-negative integer n and then compute an approximation for the value of e using the first n + 1 terms of the continued fraction: I have attempted to decipher the question but

Pandas Split column into multiple columns by multiple string delimiters

霸气de小男生 提交于 2021-02-08 15:00:27
问题 I have a dataframe: id info 1 Name: John Age: 12 Sex: Male 2 Name: Sara Age: 22 Sex: Female 3 Name: Mac Donald Age: 32 Sex: Male I'm looking to split the info column into 3 columns such that i get the final output as: id Name Age Sex 1 John 12 Male 2 Sara 22 Female 3 Mac Donald 32 Male I tried using pandas split function. df[['Name','Age','Sex']] = df.info.split(['Name']) I might have to do this multiple times to get desired output. Is there a better way to achieve this? PS: The info column