Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
ETE2 (a Python Environment for phylogenetic Tree Exploration) has a method .phonehome() which can be called on tree/node class objects. This returns:
== Calling home... Got answer!
He11o alien,
How is everything in the Earth?
We miss you in Brodo Asogi.
I see you are in shape.
No updates are available.
== Do you want to leave any message?
(Press enter to finish)
If you want to test this for yourself, try:
from ete2 import Tree
t = Tree() # generate random Tree
t.phonehome() # communicate with Aliens!
Is this an easter egg?
The project logo is:
So you could call it an easter egg. But it also has a real purpose, as it is the projects version check method, named with a pinch of humor:
''' I use this module to check for newer versions of ETE '''
and
def call():
print " == Calling home...",
try:
f = url.urlopen('http://ete.cgenomics.org/et_phone_home.php?VERSION=%s&ID=%s'
%(__VERSION__, __ETEID__))
and:
if not latest:
print "I could not find data about your version [%s]" %module_name
print "Are you ok?"
elif not current:
print "I could not determine your version [%s]" %module_name
print "Are you ok?"
print "Latest stable ETE version is", latest
elif latest > current:
print "You look a bit old."
print "A newer version is available: rev%s" %latest
print "Use 'easy_install -U %s' to upgrade" %module_name
else:
print "I see you are in shape."
print "No updates are available."
See the source code of the ete2._ph module; phonehome() calls ete2._ph.call().
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
I'm working on a simpe python code, where we have to scrap a web page and find a book for its title and topic, if the book is found then it should return true, otherwise false in a sentence like statement.
Here's the code:
books_found = parsed_content.find_all('h3')
for book in books_found:
if book.text == title:
return f'"{title}" is available in "{topic}"'
return f'"{title}" is not available in "{topic}"'
Here's the failed test case:
def test_basic_out_of_stock_queries(self):
""" basic out of stock queries """
self.assertFalse(
in_stock("While You Were Mine", "Science"),
'"While You Were Mine" is not available in "Science"'
)
self.assertFalse(
in_stock("Online Marketing for Busy Authors: Step-By-Step guide", "Self help"),
'"Online Marketing for Busy Authors: Step-By-Step guide" is not available in "Self help"'
)
And here's the failed test case response:
out of stock queries
Test Failed
Failure
AssertionError: '"While You Were Mine" is not available in "Science"'
is not false : "While You Were Mine" is not available in "Science"
So, what might be wrong here?
Since you have stated that you cannot change the test cases, I assume these are set by what ever validates your code. With this in mind the test case is testing the in_stock function and expects it to return a bool value not a string. So your stock check should be returning true or false as thats what the test case is checking for
books_found = parsed_content.find_all('h3')
for book in books_found:
if book.text == title:
return True
return False
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 20 days ago.
Improve this question
Very general question: I am attempting to write a fairly complext Python script.
#Part A: 100 lines of python code
#Part B: 500 lines of python code
#Part C: 100 lines of python code
Assume that I want "Part B" taken out of the picture for readability and debugging purposes, because I know that it is running well and I want to focus on the other parts of the code.
I would define a function like this:
def part_b():
#500 lines of python code
#Part A: 100 lines of python code
part_b()
#Part C: 100 lines of python code
The problem with this approach in my case is that there are more than twenty variables that need to be sent to "Part C". The following looks like bad practice.
def part_b():
global var1
global var2
global var3...
I am aware that I could return an object with more than twenty attibutes, but that would increase complexity and decrease readability.
In other words, is there a pythonic way of saying "execute this block of code, but move it away from the code that I am currently focusing on". This is for a Selenium automation project.
Sounds like what you're looking for is modules. Move part B into a separate file, and then import it.
import part_B
# part A here
part_B.run()
# part C here
# to access things that part B does:
do_part_C_stuff(part_B.something)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
define function, speller
if there are no more letters
print "all done"
print the first letter
invoke speller with the given name minus the first letter
If we invoked this function with “Zoe” as the argument, we would see “Z”, “o”, and “e” printed out before “all done”.
We call the function a total of 4 times!
function called with “Zoe”
function called with “oe”
function called with “e”
function called with “”
Recursive means the function should call itself from within the method:
def speller(word):
if not word:
print('all done')
return
print(word[0])
speller(word[1::])
speller('Zoe')
Output:
>> Python 3.6.8 (default, Jun 11 2019, 01:21:42)
>> [GCC 6.3.0 20170516] on linux
>> Z
>> o
>> e
>> all done
https://repl.it/repls/CoolAmusedPlots
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
Is it possible, using Python to get a value of a variable from RAM using an address, something like Cheat Engine?
It's really implementation dependent, you could try this in CPython with ctypes.string_at function (it dumps whole Python3 integer structure):
import ctypes
from sys import getsizeof
my_value_1 = int(1)
my_value_2 = int(2)
b1 = ctypes.string_at(id(my_value_1), getsizeof(my_value_1))
b2 = ctypes.string_at(id(my_value_2), getsizeof(my_value_2))
print(hex(id(b1)), ''.join(format(x, '02x') for x in b1))
print(hex(id(b2)), ''.join(format(x, '02x') for x in b2))
Prints:
0x7ffff670ffb0 4d0300000000000040b89d0000000000010000000000000001000000
0x7ffff670f5f0 740000000000000040b89d0000000000010000000000000002000000
In other implementations of Python (Jython, Iron Python etc.) this probably won't work. On CPython id() returns memory address of the object.
I found a Python module hackManager, and it solved my issue.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
What is the best way to mark deprecated fields in Django 1.4 models if I don't want to delete them right away?
Sorry, I can't comment yet.
If you don't want anything fancy you could simply compare the Python version and launch a warning.
import django
print django.VERSION
>> (1, 8, 5, 'final', 0)
if django.VERSION[1] < 4:
print "[DEPRECATION WARNING]"
Or you could do the best approach: to go to a popular package and see how they do it. For example in Django CMS:
cms/exceptions.py (https://github.com/divio/django-cms/blob/develop/cms/exceptions.py)
# -*- coding: utf-8 -*-
class Deprecated(Exception): pass
cms/utils/check.py (https://github.com/divio/django-cms/blob/develop/cms/utils/check.py)
#define_check
def check_deprecated_settings(output):
with output.section("Deprecated settings") as section:
found = False
for deprecated in ['CMS_FLAT_URLS', 'CMS_MODERATOR']:
if hasattr(settings, deprecated):
section.warn("Deprecated setting %s found. This setting is no longer in use and can be removed" % deprecated)
found = True
if not found:
section.skip("No deprecated settings found")