(url(r"^admin/", include(admin.site.urls),
( url(r"^markdown/", include("django_markdown.urls")
کلمات کلیدی:
Because lists are sequences, indexing and slicing work the same way for lists as they do for strings.
Assuming following input −
L =["spam","Spam","SPAM!"]
Source
http://www.tutorialspoint.com
Python Expression | Results | Description |
---|---|---|
L[2] | "SPAM!" | Offsets start at zero |
L[-2] | "Spam" | Negative: count from the right |
L[1:] | ["Spam", "SPAM!"] | Slicing fetches sections |
کلمات کلیدی:
Being a Python Web framework, Django requires Python. See What Python version can I use with Django? for details. Python includes a lightweight database called SQLite so you won’t need to set up a database just yet.
Get the latest version of Python at https://www.python.org/download/ or with your operating system’s package manager.
Django on Jython
If you use Jython (a Python implementation for the Java platform), you’ll need to follow a few additional steps. See Running Django on Jython for details.
You can verify that Python is installed by typing python from your shell; you should see something like:
Python 3.4.x
[GCC 4.x] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
This step is only necessary if you’d like to work with a “large” database engine like PostgreSQL, MySQL, or Oracle. To install such a database, consult the database installation information.
If you are upgrading your installation of Django from a previous version, you will need to uninstall the old Django version before installing the new version.
You’ve got three easy options to install Django:
Always refer to the documentation that corresponds to the version of Django you’re using!
If you do either of the first two steps, keep an eye out for parts of the documentation marked new in development version. That phrase flags features that are only available in development versions of Django, and they likely won’t work with an official release.
To verify that Django can be seen by Python, type python from your shell. Then at the Python prompt, try to import Django:
>>> import django
>>> print(django.get_version())
1.9
You may have another version of Django installed.
کلمات کلیدی:
خواندن انسان را کامل میکند؛ سخنرانی او را میسازد و نوشتن به او دقت میآموزد. "ناشناس"
کلمات کلیدی:
Design, develop, and enhance infrastructure primarily using Python and Django to build a platform that manages operational business flows.
Business Intelligence(BI) and ERP services and solutions.
Python, django expert. My objective is to learn, and solve people"s problems with everything I do and create in the best way I can think of.
TOP Django provider on Elance We are outsourcing software company based in Europe.
Source
Elance.com
کلمات کلیدی:
چگونه افراد موفق استرس خود را کنترل می کنند؟ 78-1 افراد دو گروه هستند. گروه اول، آن دسته از مردمی که باور دارند شخصا قادر به انجام تمامی کارها هستند و رویدادهای پیشآمده در زندگی شخصی و حرفهای کم و بیش تحت کنترل آنها است؛ اما گروه دیگر معتقدند خود دخالتی در وقوع اتفاقات پیشآمده ندارند و بیشتر خود را به جریانات زندگی میسپارند. کلیک کنید و بخوانید: شوخی کنید، کمتر استرس بگیرید تیم جاج، روانشناس دانشگاه فلوریدا و همکارانش پس از بررسیهای به عمل آمده به این نتیجه رسیدند افرادی که احساس میکنند کنترل اتفاقات رخ داده در زندگی را بر عهده دارند به تواناییهای خود در انجام کارها اطمینان داشته و تقریبا از عهده انجام هر گونه اقدام مهمی برمیآیند. تیم جاج در مطالعات خود به این نتیجه رسید که این دسته از افراد که از این پس آنان را افراد مقتدر مینامیم، کارهایی نظیر موارد زیر را انجام میدهند: 1- میزان فروش بیشتر نسبت به کارمندان دیگر 2- ارائه خدمات عالیتر به مشتریان 3- مطابقت بهتر با وظایف جدید 4- کسب درآمد سالانه بهطور متوسط پنجاه تا صد و پنجاه درصد بیشتر. در شرایط خوب و بد هر چند که اکثر افراد، زمانی که اوضاع بر وفق مراد است معتقد هستند که از اعتماد به نفس و فرصت بالایی برخوردار هستند، اما براساس مطالعات انجام شده از سوی «تیم جاج»، آنچه صاحبان قدرت را خاص میکند این نکته است که چه آنها در کارگاه مشغول به فعالیت باشند یا در کسبوکار شخصی خود، دقیقا شبیه دیگران در شرایط دشوار احساس نگرانی شدید کرده اما از این احساس به طرز متفاوتی استفاده میکنند و هرگز به هنگام وقوع مشکلات از پای درنمیآیند. افراد قدرتمند، معتقد هستند بر رویدادهای زندگی خود مانند اضطراب، ناامیدی، سرسختی و بیم و هراس کنترل دارند، هرگز تسلیم نشده بلکه در شرایط دشوار، تلاش خود را چندین برابر میکنند. نحوه عملکرد اضطراب یک احساس کاملا ضروری است و اگر گمان میکنید که هرگز آن را تجربه نکرده اید، شاید متوجه چنین حسی نشدهاید. رفتار مغز انسان به گونهای است که تا زمانی احساس اضطراب نکرده است انجام هر گونه عملی برای آن دشوار است. به عبارت دیگر، افزایش میزان بالای فعالیت با سطح مناسبی از اضطراب همراه است و اما یک راهحل پیشنهادی بهمنظور دستیابی به عملکرد عالی: میزان اضطراب را کنترل کنید و آن را در سطوح مطلوبی نگاه دارید. اگر شرایط لازم برای کنترل اضطراب به هنگام هیجانات شدید را ندارید، هرگز متوجه قدرت و پتانسیل کامل خود نخواهید شد. به هنگام مواجهه با شرایط دشوار و نامطمئن و بروز احساس اضطراب، باید بتوانید اضطراب خود را کنترل کنید. کلیک کنید و بخوانید: شلیک به استرس در محل کار تنها لازم است مراحلی را که افراد موفق و توانمند برای کنترل اضطراب در پیش گرفتهاند، انجام دهید. نکته کلیدی بهمنظور درک چنین موضوعی پیش از شروع کار، روبهرو شدن با ابهامات و آینده است که هنوز برای شما رقم نخورده است. این موضوع کاملا به شما بستگی دارد تا باورها و توان ذهنی خود را بهبود بخشید تا قطعا به یکی از افراد توانمند تبدیل شوید. نحوه انجام کار مرحله 1: انتظار و آمادگی برای تغییر همانطور که افراد تغییر میکنند، کسبوکار نیز، از این قاعده مستثنی نیست و دچار نوسانات میشود. طبق مطالعاتی که «تیم جاج» انجام داد، حتی اشخاص قدرتمند هم کنترلی بر تغییرات در کسبوکار ندارند و احتمال اینکه شغل خود را از دست بدهند، زیاد است. طبعا شرکتهایی که در آن، مشغول به فعالیت هستند نیز دستخوش شرایط بحرانی و سختی بودهاند؛ اما تفاوت در این نکته است که چنین افرادی معتقد هستند کاملا از عهده ایجاد اتفاقات مثبت بر میآیند و میتوانند با تغییرات، سر و کار داشته باشند. به عبارت دیگر، از نظر ذهنی، آمادگی ذهنی لازم برای تغییرات را دارند و شما هم میتوانید رفتاری مانند افراد مقتدر داشته باشید. اگر تغییرات را بهطور طبیعی پیشبینی نکنید، لازم است زمانی را بهطور منظم (به عنوان مثال هر هفته یا چند هفته یک بار) اختصاص دهید به تهیه لیستی از تغییرات مهمی که تصور میکنید باید در زندگی شخصی شما اتفاق افتد، هدف از انجام این کار، پیشبینی هر تغییری که با آن روبهرو خواهید شد، نیست بلکه ذهن شما نسبت به تغییرات و تقویت توانایی برای تشخیص و پاسخگویی به تغییرات قریبالوقوع، آماده خواهد شد. حتی اگر حوادث موجود در فهرستی که آماده کردهاید هرگز به وقوع نپیوندند، تمرین پیشبینی و آمادگی برای وقوع تغییرات، قابلیت بیشتری برای مواجهه با آینده را به شما خواهد داد و میتوانید بر ابهامات حاصل از تغییرات فائق آیید. مرحله 2: تمرکز روی آزادیها و نه محدودیتها تمام افراد از زمان جوانی خود با یک باور قدیمی که «زندگی عادلانه نیست»، آشنایی دارند. این باور، نشانه ناامیدی، اضطراب و سستی است. به راستی، جلوگیری از پیشامدها، اتفاقات منفی گاهی اوقات از عهده افراد خارج است؛ اما برای انتخاب واکنش مناسب در قبال رویدادهای پیش آمده هیچ محدودیتی وجود ندارد و انسانها در این مسیر آزاد هستند. تمام روشهای مثبت برای انجام کار و پاسخ به هر تغییر را در لیستی که از تغییرات احتمالی در مرحله یک تهیه کردید، یادداشت کنید. مطمئنا از اینکه تا چه حد قابلیت نظارت بر واکنشهای ظاهرا غیر قابل کنترل را دارید، تعجب خواهید کرد. مرحله 3: بازسازی ساختار فکری مرحله سوم، دشوارترین مرحله بهشمار میرود؛ زیرا باید طرز تفکری را که سالها به آن عادت کردهاید، تغییر دهید. با گذشت زمان، انسانها، طرز تفکر و همچنین احساسی که از شرایط دارند و واکنش خود را نسبت به مسائل مختلف، تغییر داده و ارتقا میبخشند. این طرز فکرها تا جایی پیش میروند که برای گفتار و رفتار افراد، در شرایط مختلف تصمیمگیری میکنند. برای نتیجهگیری بهتر و قدرتمندتر شدن، لازم است تا در طرز فکر خود تجدید نظر کنید. برای این منظور، یادآوری و مرور شرایط دشواری که اخیرا با آن درگیر بودهاید، کمک فراوانی میکند. مهم است که بدانید چه باورهایی در زندگی شما وجود دارد که با واکنشهای موثرتر و شرایط بهتر در زندگیتان در تضاد است. متن را تهیه کنید و نام آن را عوامل بازدارنده بگذارید. از آن جا که در حال حاضر، نسبت به اتفاقاتی که در گذشته رخ داده درک و دید بهتری دارید، متنی حاصل از ذهنی مقتدر و موثر که قصد داشتید از آن پیروی کنید، آماده کنید. این متن، اقتدار نام دارد و جایگزین متن عوامل بازدارنده خواهد شد. این مطالب را به نحوی بایگانی کنید که در مواقع لزوم و هنگام مواجهه با استرس و اضطراب شدید به آنها دسترسی داشته باشید و به هنگام مراجعه، تفکر در حال حاضر خود را با نوشتههای توانمند و عوامل بازدارنده خود مقایسه کنید. با انجام این کار، با خود صادق باقی میمانید و رفتار و عملکرد خود را با متن اقتدار خود تطبیق خواهید داد. این یادآوریهای دورهای، در نهایت باعث بازنگری و بازسازی کامل طرز فکر شما خواهد شد و موجب میشود تا عملکردتان همیشه بر اساس طرز فکری قوی استوار باشد. مرحله 4: کنار گذاشتن افکار منفی یک مرحله مهم در مدیریت اضطراب، کنار گذاشتن و دوری کردن از صحبتها و افکار منفی است. هر اندازه به افکار منفی اهمیت دهید و ذهن خود را بیشتر درگیرشان کنید، به آنها قدرت و بال و پر بیشتری میدهید. بسیاری از تفکرات منفی واقعیت نداشته و چیزی جز افکار نیستند. زمانی که متوجه باور عمیق خود به مسائل بدبینانه و منفی برگرفته از درون شدید، زمان آن فرارسیده است که چنین افکاری را کنار گذاشته و تمام تفکرات را در دفتری یادداشت کنید. به محض اینکه سعی کنید تا از میزان افکار منفی خود بکاهید مطمئنا در بررسی صحت افکار منفی، منطقیتر و هوشیارانهتر عمل خواهید کرد. مطمئنا گفتههای شما زمانی که از کلماتی نظیر «هرگز»، «بدترین حالت» یا «همیشه» استفاده میکنید، واقعیت ندارد. اگر اظهاراتی را که یادداشت کردهاید هنوز واقعی به نظر میرسند به یک دوست یا همکار قابل اعتماد خود نشان دهید و نظر وی را هم در این باره جویا شوید که آیا با شما هم عقیده است یا خیر! سپس حقیقت مطمئنا مشخص خواهد شد. زمانی که احساس میکنید رویدادی مدام در حال رخ دادن است یا بر عکس، هرگز اتفاق نمیافتد، منشا این احساس واکنشهای مغز شما در قبال تهدیدهای گذشته و میزان درک شما از واقعه و شدت آن است. سعی کنید با تفکیک افکار از حقایق، از حصار چرخه منفی و اضطراب خلاص شوید تا شاهد آینده جدید و مثبتی در زندگی باشید. مرحله 5: قدردانی از داشتهها صرف کردن زمان زیاد جهت بررسی داشتهها در زندگی و رضایت کامل کار زیاد صحیحی نیست اما این عمل موجب کاهش اضطراب در افراد میشود زیرا میزان هورمون کورتیزول(استرس) را تا 23 درصد کاهش میدهد. بر اساس تحقیقات انجام شده در دانشگاه کالیفرنیا، افرادی که در طول روز بر رفتار و ذهن خود برای قدردانی از داشتههایشان تاکید میکنند و آن را گسترش میدهند از شرایط و انرژی بیشتری برخوردار هستند و در واقع اضطراب کمتری را به علت سطوح کورتیزول پایینتر، تجربه میکنند. اضطراب طاقتفرسا و اقتدار با یکدیگر در تضاد هستند. زمانی که میخواهید بر محدودیت عملکرد خود با اضطراب کافی غلبه کنید، فقط کافی است به مراحل اشاره شده این مقاله، عمل کنید تا خود را قدرتمند سازید و کنترل امور را دوباره به دست بگیرید. مترجم: هوتسا عسکری نسب
Source
Forbes
کلمات کلیدی:
:(def visit_Module(self, node
print"Module : %s"% node
I basically need the actual module name If it is inside a package then the complete one like a.b.module
:if len (trashed_files) == 0
From executing Python code, you can use__name__
and__package__
from inside Python code
The compiler.ast module is generated from a text file that describes each node type and its elements. Each node type is represented as a class that inherits from the abstract base class compiler.ast.Node and defines a set of named attributes for child nodes
Sources
Python.org
Stackoverflow.com
کلمات کلیدی:
As part of our XML"99 coverage, we are pleased to bring you this taster from the "Working with XML in Python" tutorial led by Sean McGrath.
A century ago, when HTML and CGI ruled the waves, Perl dominated the Web programming scene. As the transition to XML on the Web gathers pace, competition for the hearts and minds of Web developers is heating up. One language attracting a lot of attention at the moment is Python
In this article we will take a high level look at Python. We will use the time honored "Hello world" example program to illustrate the principle features of the language. We will then examine the XML processing capabilities of Python
Python is free. You will find downloadable source code plus pre-compiled executables on python.org. As you know, "free" is one of those words that is often heavily loaded on the Internet. Fear not. Python is free with a capital "F". You are free to do essentially anything you like with Python, including make commercial use of it or derivatives created from it
Python is an interpreted language. Programs can execute directly from the plain text files that house them. Typically Python files have a .py
extension. There is no compilation phase as far as the programmer is concerned. Just edit and run
Python is portable. It runs on basically every computing platform of note, from mainframes to Palm Pilots and everything in between. Python uses a virtual machine architecture, similar in concept to Java"s virtual machine. The Python interpreter "compiles" programs to virtual machine code on-the-fly. These compiled files (typically having a .pyc
extension) are also portable. That is to say, if you wish to keep your source files hidden from your end-users you can simply ship the compiled .pyc
files
Python is very easy to understand. Here is a Python program that prints the string "Hello world"
print "Hello world"
I think you will agree that programming a "Hello world" application cannot get much simpler than that! To execute this program, you put it in a text file, say Hello.py
, and feed it to the Python interpreter like this
python Hello.py
The output is, surprise, surprise
Hello world
Note the complete lack of syntactic baggage in the Hello.py
program. There are no mandatory keywords or semi-colons required to get this simple job done. This spartan, no-nonsense approach to syntax is one of the hallmarks of Python and applies equally well to large Python programs.
By invoking the Python interpreter (typically by typing python
on a UNIX/Linux system, or running the "IDLE" application on Windows), you will find yourself in an environment where you can execute Python statements interactively. As an example, here is the "Hello world" application again:
>>> print "Hello world"
This will output
Hello world
Note that the ">>>" above is Python"s command prompt. The interactive mode is an excellent environment for playing around with Python. It is also indispensable as a fully programmable calculator
Python is sometimes referred to as a WYSIWYG programming language. This is because the indentation of Python code controls how the code is executed. Python does not have begin/end keywords or braces for grouping code statements. It simply does not need them. Take a look at the following Python fragment
if x > y
print x
if y > z
print y
print z
else
print z
The indentation of the code is used to control how statements are grouped for execution purposes. There can be no ambiguity as to which if
clause is associated with the else
clause in the above code because both statements have same level of indentation.
We can turn the "Hello world" program into a Python function like this
def Hello()
print "Hello world"
Note that statements within the body of a function are indented beneath the def Hello()
line which introduces the function. The parenthesis are a place holder for function parameters. Here is a function that prints its parameters x
and y
as well as the string "Hello world":
def Hello(x,y)
print "Hello world",x,y
A Python program typically consists of a number of modules. Any Python source file can serve as a module and be imported into another Python program. For example, assuming the Hello
function above is housed in the file Greeting.py
we can import the function into a Python program and call it as follows
# Import the Hello function from the Greeting module
from Greeting import Hello
# Call the Hello function
Hello()
Python makes it easy to write programs that can be used both as stand-alone programs and as modules to other programs.
Here is a modified version of Greeting.py
which will print "Hello world" but can also still be imported into other programs
def Hello()
print "Hello world"
if __name__ == "__main__"
# Test Hello Function if running as
# main program
Hello()
Note the special __name__
variable above. This variable is automatically set to "__main__"
when a program is being executed directly. If it is being imported into another program, __name__
is set to the name of the module, which in this case would be "Greeting"
Python is a very object-oriented language. Here is an extended version of the "Hello world" program, called Message.py
, that can print any message via MessageHolder
objects
#Create a class called MessageHolder
class MessageHolder:
# Constructor - called automatically
# when an object of this class is created
def __init__(self,msg)
self.msg = msg
# Function to return the stored message string
def getMsg(self)
return self.msg
Note how indentation is used to structure the source code. the getMsg
function is associated with objects of the MessageHolder
class because it is indented beneath the class MessageHolder
. Functions associated with objects are more generally known as methods
Suppose now that I need a variation on the MessageHolder
class in which all messages are returned in uppercase. I can do that by subclassing MessageHolder
, specifying the class I wish to inherit from in parentheses after the class name
# Import existing MessageHolder class from Message.py
from Message import MessageHolder
# Create a sub-class of MessageHolder called MessageUpper
class MessageUpper(MessageHolder)
# Constructor
def __init__(self,msg)
# Call constructor of superclass
Message.__init__(msg)
# Over-ride getMsg with new
# functionality
def getMsg(self)
return string.upper(self.msg)
The Python language consists of a small core and a large collection of modules. Some of these modules are written in Python and some are written in C. As a user of Python modules, you cannot tell the difference. For example
import xmlproc
import pyexpat
The first statement imports Lars Marius Garshol"s implementation of an XML parser that is written purely in Python. The second statement imports the Python wrapping of James Clark"s expat XML parser which is written in C
Python programs using these modules cannot tell what language they have been implemented in. As you would expect, programs based on expat are typically faster owing to the speed advantages of a pure C implementation of an XML parser.
It is remarkably easy to write a Python module in C. This facility is very useful for speed-critical parts of large Python systems. It is also easy to "wrap" existing C libraries as Python modules, as has been done with expat. Many technologies exposing a C API have been wrapped as Python modules, for example Oracle, the Win32 API, and the wxWindows GUI toolkit, to name a few
The core Python distribution (currently at version 1.5.2) has a simple non-validating XML parser module called xmllib
. The vast bulk of Python"s XML support is in the form of an add-on module under active development by the SIG for XML Processing in Python (known as XML-SIG). To illustrate Python"s XML support, we will switch to an XML 1.0 version of the "Hello world" program processing the following file
<?xml version = "1.0"?>
<Greeting>
Hello world
</Greeting>
SAX is a simple API for XML, spearheaded by David Megginson and developed as a collaborative effort on the XML-dev mail list. The Python implementation was developed by Lars Marius Garshol.
A Python SAX application to count the words in Greeting.xml
looks like this
from xml.sax import saxexts, saxlib, saxutils
import string
# Create a class to handle document events
class docHandler(saxlib.DocumentHandler)
# Start of document handler
def startDocument(self)
# Initialize storage for character data
self.Storage = ""
# end of document handler
def endDocument(self)
# Print approximate number of words
# by counting the number of elements in
# the list of words returned by the
# string.split function
print len(string.split(self.Storage))
def characters(self,str,start,end)
# Accumulate character data
self.Storage = self.Storage + str[start:end]
# Create a parser
parser = saxexts.make_parser()
# Provide the parser with a document handler
parser.setDocumentHandler(docHandler())
# Parse the Greeting.xml file
parser.parseFile(open("Greeting.xml"))
The DOM is a W3C initiative to standardize an API to XML (and HTML) documents. Python has two DOM implementations. The one in the XML-SIG modules is the work of Andrew Kuchling and St?fane Fermigier. The other is called 4DOM and is the work of Fourthought, who have also created XSLT and XPath implementations in Python.
Here is a sample DOM application to count the words in Greeting.xml
from xml.dom import utils,core
import string
# Read an XML document into a DOM object
reader = utils.FileReader("Greeting.xml")
# Retrieve top level DOM document object
doc = reader.document
Storage = ""
# Walk over the nodes
for n in doc.documentElement.childNodes:
if n.nodeType == core.TEXT_NODE:
# Accumulate contents of text nodes
Storage = Storage + n.nodeValue
print len(string.split(Storage))
As well as industry standard APIs, there is a native Python XML processing library known as Pyxie.
Pyxie is an open source XML processing library for Python which will be made publicly available in January 2000. Pyxie tries to make the best of Python"s features to simplify XML processing.
Here is the word counting application developed using Pyxie
from pyxie import *
# Load XML into tree structure
t = File2xTree("Greeting.xml")
Storage = ""
# Iterate over list of data nodes
for n in Data(t)
Storage = Storage + t.Data
print len(string.split(Storage))
We have looked at some of the main features of Python in a high level way. Also, we have glimpsed at some of the XML processing facilities available. For further information on programming with Python, I suggest you start with http://www.python.org
Future articles on XML.com will taker a closer look at implementing XML applications in Python
Source
XML.com
کلمات کلیدی: