Difference between revisions of "Category:Python"

From ElectroDragon
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
== Sub-category ==
 +
* [[Micropython]]
 +
== Basic==
 +
{| class="wikitable sortable"
 +
|-
 +
! Command !! description!! example !! Header text
 +
|-
 +
| comment || # for line, """ and """ for paragraph || Example || Example
 +
|-
 +
| print || Example || print("234") # print string; print 234 # print variable|| Example
 +
|-
 +
| linux bash run || #! /usr/bin/python || Example || Example
 +
|-
 +
| Example || Example || Example || Example
 +
|}
 +
 +
== Format ==
 +
=== String Format ===
 +
<syntaxhighlight lang="python">
 +
print("I'm %s. I'm %d year old" % ('Vamei', 99))
 +
print ('this is %s %%') (% date) # %% to print %
 +
</syntaxhighlight>
 +
* s.strip() .lstrip() .rstrip(',') remove empty space, and special words
 +
 +
=== Format type ===
 +
* print type(aaa) # print type of aaa variable
 +
* print len(aaa) # print length
 +
 +
=== Change format ===
 +
a = float(b) change to type float
 +
=== Module String ===
 +
==== Replace ====
 +
<syntaxhighlight lang="python">
 +
import string
 +
a = 'abcde'
 +
b = string.replace(a, 'ab', '', 1)
 +
print b
 +
</syntaxhighlight>
 +
 +
== file operation ==
 +
<syntaxhighlight lang="python">
 +
    myfile = open('/srv/www/idehe.com/stock/data.txt', 'w')
 +
    myfile.writelines('\n')   
 +
    myfile.close()
 +
 +
    myfile = open('/srv/www/idehe.com/stock/data.txt', 'a')            # open for output (creates)
 +
    myfile.writelines('\n')
 +
    myfile.writelines(line1)        # write a line of text
 +
    myfile.writelines('\n') 
 +
    myfile.writelines(line2)        # write a line of text
 +
    myfile.close()
 +
</syntaxhighlight>
 +
 +
== Operation ==
 +
not is evaluated first; and is evaluated next; or is evaluated last.
 +
 +
== Group, List, Dict==
 +
* group = (), list = [], dict = {}
 +
=== List ===
 +
* L[2] 'SPAM!' read the third element
 +
* L[-2] 'Spam' red the last third element
 +
* L[1:] ['Spam', 'SPAM!'] cut the list from the second element
 +
 +
== Module/Library ==
 +
Installation by:
 +
* pip install
 +
* manually in folder by: python setup.py install
 +
* pip install xxxx.whl file
 +
* Socket - https://docs.python.org/2/library/socket.html#example
 +
* PIL / Pillow -> pip install pillow -> when missing Image module
 +
List Modules
 +
* bs4, BeautifulSoup, feedparser,
 +
* python -m pip install mysql-connector
 +
* python -m pip install flask
 +
* python -m pip install uwsgi
 +
 +
== Pratical Test ==
 +
* for loop
 +
for x in range (xxx, 0, -1):
 +
 +
== Project ==
 +
install/unstall a library, first install pip: apt-get install python-pip
 +
pip install datetime
 +
pip uninstall datetime
 +
common used library
 +
* Datetime
 +
* Django
 +
=== Kivy ===
 +
==== For android ====
 +
* install debian jessie, install python-kivy, python-pip
 +
* install buildozer (pip install), java SDK (default-jdk), cython, etc
 +
* buildozer init, and run: buildozer set default android_new debug deploy run, android USB debug should turn on
 +
* buildozer need ANT, SDK, NDK on first time
 +
 +
==== Other ====
 +
* [[python-web]]
 +
 +
== Reference ==
 +
* https://www.codecademy.com/learn
 +
* symbol review: http://learnpythonthehardway.org/book/ex37.html
 +
 +
 +
 +
Python
 +
* [https://www.python.org/downloads/release/python-352/ Python 3.52 download page here.]
 +
 
== Libraries ==
 
== Libraries ==
 
=== OS ===
 
=== OS ===
 
* list dir -> import os -> os.listdir("\"), list sd card -> os.listdir("\sd")
 
* list dir -> import os -> os.listdir("\"), list sd card -> os.listdir("\sd")
[[category: Python]]
+
=== REPL ===
 +
* execfile('filename.py')
 +
[[category: Software]]

Latest revision as of 15:08, 5 February 2020

Sub-category

Basic

Command description example Header text
comment # for line, """ and """ for paragraph Example Example
print Example print("234") # print string; print 234 # print variable Example
linux bash run #! /usr/bin/python Example Example
Example Example Example Example

Format

String Format

print("I'm %s. I'm %d year old" % ('Vamei', 99))
print ('this is %s %%') (% date) # %% to print %
  • s.strip() .lstrip() .rstrip(',') remove empty space, and special words

Format type

  • print type(aaa) # print type of aaa variable
  • print len(aaa) # print length

Change format

a = float(b) change to type float

Module String

Replace

import string
a = 'abcde'
b = string.replace(a, 'ab', '', 1)
print b

file operation

    myfile = open('/srv/www/idehe.com/stock/data.txt', 'w')
    myfile.writelines('\n')    
    myfile.close()

    myfile = open('/srv/www/idehe.com/stock/data.txt', 'a')             # open for output (creates)
    myfile.writelines('\n')
    myfile.writelines(line1)        # write a line of text
    myfile.writelines('\n')   
    myfile.writelines(line2)        # write a line of text
    myfile.close()

Operation

not is evaluated first; and is evaluated next; or is evaluated last.

Group, List, Dict

  • group = (), list = [], dict = {}

List

  • L[2] 'SPAM!' read the third element
  • L[-2] 'Spam' red the last third element
  • L[1:] ['Spam', 'SPAM!'] cut the list from the second element

Module/Library

Installation by:

List Modules

  • bs4, BeautifulSoup, feedparser,
  • python -m pip install mysql-connector
  • python -m pip install flask
  • python -m pip install uwsgi

Pratical Test

  • for loop
for x in range (xxx, 0, -1):

Project

install/unstall a library, first install pip: apt-get install python-pip

pip install datetime
pip uninstall datetime 

common used library

  • Datetime
  • Django

Kivy

For android

  • install debian jessie, install python-kivy, python-pip
  • install buildozer (pip install), java SDK (default-jdk), cython, etc
  • buildozer init, and run: buildozer set default android_new debug deploy run, android USB debug should turn on
  • buildozer need ANT, SDK, NDK on first time

Other

Reference


Python

Libraries

OS

  • list dir -> import os -> os.listdir("\"), list sd card -> os.listdir("\sd")

REPL

  • execfile('filename.py')

Subcategories

This category has only the following subcategory.

Pages in category "Python"

The following 10 pages are in this category, out of 10 total.