Форум сайта python.su
# -*- coding: utf-8 -*-
import sys
def ssize(s):
if type(s) == unicode: return sys.getsizeof(s)-sys.getsizeof(u'')
else: return sys.getsizeof(s)-sys.getsizeof('')
print ssize('При вет') # 13
print ssize(u'При вет') # 14
list_int=map(lambda x: int(x),list_str[0].split(','))
def parse_search(url):
try:
parsed = urlparse.urlsplit(url)
network = parsed[1]
query = parsed[3]
except (AttributeError, IndexError):
return (None, None, None)
for engine, param in SEARCH_PARAMS.iteritems():
match = re.match(NETWORK_RE % engine, network)
if match and match.group(2):
term = cgi.parse_qs(query).get(param)
if term and term[0]:
term = ' '.join(term[0].split()).lower()
return (engine, network, term)
return (None, network, None)
logging.info("term: %s", term)
[I 091113 14:08:11 demo:333] term: ñ�ðµðºñ� ñˆð
term = simplejson.dumps(term)
'term': '"\\u00f1\\u0081\\u00f0\\u00b5\\u00f0\\u00ba\\u00f1\\u0081 \\u00f1\\u0088\\u00f0\\u00be\\u00f0\\u00bf"',
'title': u'\u0421\u0435\u043a\u0441 \u0448\u043e\u043f'
term = (urllib.unquote_plus(term))
'term': u'\xf1\x81\xf0\xb5\xf0\xba\xf1\x81 \xf1\x88\xf0\xbe\xf0\xbf'
u'\u0421\u0435\u043a\u0441 \u0448\u043e\u043f'
# coding: utf-8
import time
counter = 0
start = time.ctime()
def application(environ, start_response):
global counter,start
counter += 1
status = '200 OK'
output = 'Start time: %s<br/>\nCounter: %d' % (start,counter)
response_headers = [('Content-type', 'text/html; charset=utf-8'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
# -*- coding: cp1251 -*-
from Tkinter import *
import sys
import time
from TableList import *
class Aplication(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
# Пакуем окошко
self.pack()
#Создаем виджеты
self.createWidgets()
def createWidgets(self):
#Узнаем размеры экрана и задаем минимальные и максимальные размеры окна, тут у нас всё максимально
self.master.maxsize(self.winfo_screenwidth(),self.winfo_screenheight())
self.master.minsize(self.winfo_screenwidth(),self.winfo_screenheight())
self.master.title = "Справочник"
#Создаем рамку не всё окно, чтобы можно было применять различные менеджеры
self.mframe = Frame(self)
self.mframe.width = self.winfo_screenwidth()
self.mframe.height = self.winfo_screenheight()
#Растягиваем рамку на все окно
self.mframe.pack(expand = YES)
#Создаем панель инструментов
self.toolbar = Frame(self.mframe)
self.toolbar["borderwidth"]=2
self.toolbar["relief"]=RAISED
# self.toolbar.pack(fill=X)
#Нихай занимает 10% по высоте
self.toolbar.place(relx= 0.1, rely=1)
#Место для таблички
self.work = Frame(self.mframe)
self.work["borderwidth"]=2
self.work["relief"]=RAISED
# self.work.pack(fill = BOTH)
#нихай занимает 80% окна
self.work.place(relx=0.8, rely=1)
# панель статуса
self.statusbar = Frame(self.mframe)
self.statusbar["borderwidth"]=2
self.statusbar["relief"]=RAISED
# self.statusbar.pack(fill = X)
#Нихай занимает 10%
self.statusbar.place(relx=0.1,rely=1)
#Ну тут в панель инструментов кидаем всякие кнопки
self.butAdd = Button(self.toolbar,text = "Добавить")
self.butAddPap = Button(self.toolbar,text = "Группа")
self.butDel = Button(self.toolbar,text = "Удалить")
self.butSelFiltr = Button(self.toolbar,text = "Фильтр")
self.butDelFiltr = Button(self.toolbar,text = "Удалить фильтр")
self.butAdd.pack(side=LEFT)
self.butAddPap.pack(side=LEFT)
self.butDel.pack(side=LEFT)
self.butSelFiltr.pack(side=LEFT)
self.butDelFiltr.pack(side=LEFT)
# +++++++++++++++++++++++++++Таблица+++++++++++++++++++++++++++++++++++++++++
tl = TableList(self.work, stretch='all', showarrow=True, columns = (5, 'Код', 0, "Название", "left", 0,"Примечание", 'right'),
)
tl.pack(fill="both")
tl.columnconfigure(0, showlinenumbers=True,)
tl.columnconfigure(1, sortmode='ascii', sortcommand='sortbycolumn')
tl.columnconfigure(2, sortmode='ascii', sortcommand='sortbycolumn')
tl.curselection()
#Ну и статус чтоб не был пустым
self.message = Label(self.statusbar, text='Привет, библиотека Tk!')
self.fortime = Label(self.statusbar, text= time.time() )
self.message.pack(side =LEFT)
self.fortime.pack(side = RIGHT )
#Усё пр херим
def die(self):
sys.exit(0)
#Ну тут шоб можно было опробывать
if __name__ == "__main__" :
app = Aplication()
app.mainloop()
CLIENTHOST = '192.168.1.1'
CLIENTPORT = 33333
SERVERHOST = '192.1681.2'
SERVERPORT = 33335
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((CLIENTHOST, CLIENTPORT))
sock.sendto(str(chr(100)),(SERVERHOST,SERVERPORT))
def safe_open(*args):
try:
return open(*args)
except IOError:
sys.exit('Error when opening file \'{0}\'. Error #{1[0]}: {1[1]}'.format(\
args[0], sys.exc_info()[1].args))
...
with safe_open(myfile, 'r') as f:
for i in f:
print i
with safe_open(anotherfile, 'r') as f:
try:
conf = ''.join(f).format(**args)
except KeyError:
quit('\nOops, your template \'{0}\' has placeholders for parameters\nthat were not supplied in the command line: - {1}\n\nCan\'t proceed. Ending. Nothing has been changed yet.'.format(args['host_template'], '\n - '.join(sys.exc_info()[1].args)), 1)
articles=sa.Table('articles',meta.metadata,
sa.Column('id',sa.types.Integer,primary_key=True,autoincrement=True,nullable=False),
sa.Column('name',sa.types.String(255),default=u'',nullable=False),
)
news=sa.Table('news',meta.metadata,
sa.Column('id',sa.types.Integer, primary_key=True, autoincrement=True,nullable=False),
sa.Column('name',sa.types.String(255),default=u'',nullable=False),
)
news_tag=sa.Table('news_tag',meta.metadata,
sa.Column('new_id',sa.types.Integer,sa.ForeignKey('news.id'),nullable=False,default=0),
sa.Column('article_id',sa.types.Integer,sa.ForeignKey('articles.id'),nullable=False,default=0),
)
class Articles(object):
def __repr__(self):
return self.name
class News(object):
def __repr__(self):
return self.name
orm.mapper(Articles,articles)
orm.mapper(
News,news,
properties={'articles':orm.relation(Articles,secondary=news_tag,backref=orm.backref('news'))}
)