virtualenv is the Python 2 tool to interact with virtual environments and won't be discussed here. I'll focus on Python 3 tools and methods only.
The Python 3 tool to manage virtual environments is venv, which —depending on your distro / version :
(myVirtualEnvironmentName)
showing the virtual environment is enabled.
#!/usr/bin/env python3 class Person(object): def __init__(self, firstName, lastName, age): self.firstName = firstName self.lastName = lastName self.age = age def getItem(self, itemName): return getattr(self, itemName) user = Person('John', 'Smith', 42) for item in [ 'firstName', 'lastName', 'age' ]: print(user.getItem(item))will display :
John Smith 42
some python code
is code stored in a fileimport math print(math.pow(2,38))
274877906944.0
Next level : http://www.pythonchallenge.com/pc/def/274877906944.html
inTable = 'KOE' outTable = 'MQG' message = 'KOE' print(message.translate({ord(x): y for (x, y) in zip(inTable, outTable)}))
MQG
List comprehensions provide a more concise way to create lists in situations where nested loops would currently be used.
print({x: y for (x, y) in zip(inTable, outTable)})
{'K': 'M', 'E': 'G', 'O': 'Q'}
print({ord(x): y for (x, y) in zip(inTable, outTable)})
{75: 'M', 69: 'G', 79: 'Q'}
inTable = 'abcdefghijklmnopqrstuvwxyz' outTable = 'cdefghijklmnopqrstuvwxyzab' message = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj." print(message.translate({ord(x): y for (x, y) in zip(inTable, outTable)}))
i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.
inTable
and outTable
strings :
import string inTable = string.ascii_lowercase outTable = string.ascii_lowercase[2:] + string.ascii_lowercase[:2]
Next level : http://www.pythonchallenge.com/pc/def/ocr.html
The question is in the HTML source :
find rare characters in the mess below: %%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{* @##&{#&{&)*%(]{{([*}@[@&]+!!*{)!}{%+{))])[!^})+)$]#{*+^((@^@}$[**$&^{$!@#$%)!@(& +^!{%_$&@^!}$_${)$_#)!({@!)(^}!*^&!$%_&&}&_#&@{)]{+)%*{&*%*&@%$+]!*__(#!*){%&@++ !_)^$&&%#+)}!@!)&^}**#!_$([$!$}#*^}$+&#[{*{}{((#$]{[$[$$()_#}!@}^@_& ...
localFile='./level02.txt'; >"$localFile"; wget -O "$localFile" http://www.pythonchallenge.com/pc/def/ocr.html; sed -i '38,1257 !d' "$localFile"; sed -ri 'sa[][)({}@%&$_+*^#!]aag' "$localFile"; sed -i '/^$/ d' "$localFile"; tr '\n' '\0' < "$localFile"
Next level :
#!/usr/bin/env python3 import lxml.etree as ET dom = ET.parse('data.xml') xslt = ET.parse('stylesheet.xsl') transform = ET.XSLT(xslt) newdom = transform(dom) print(ET.tostring(newdom, pretty_print=True))
import datetime from datetime import datetime, timedelta timeFormat = '%Y-%m-%d %H:%M:%S' now = datetime.now() print(now.strftime(timeFormat)) future = now + timedelta(seconds=500) print(future.strftime(timeFormat))