Форум сайта python.su
def num(ch_, te_): """This function is required in the correct form of presentation a couple of numbers and nouns""" import pymorphy2 morph = pymorphy2.MorphAnalyzer() word = morph.parse(te_)[0].normal_form butyavka = morph.parse(word)[0] wo_ = str(ch_) + ' ' + butyavka.make_agree_with_number(ch_).word return wo_
# -*- coding: utf-8 -*- import telebot import shelve from threading import Lock bot = telebot.TeleBot(config.token) lock = Lock() @bot.message_handler(commands=['stats']) def stats(message): chat_id=str(message.chat.id) lock.acquire() res=shelve.open(res_name,writeback=True) #какие-то команды res.close() lock.release() if __name__ == '__main__': bot.polling(none_stop=True)
def test(url, town): file = urllib.request.urlopen(url) data = file.read() file.close() current_day = datetime.datetime.now() forecasts = [] # парсю xml dom = parseString(data) forecast = dom.getElementsByTagName('FORECAST') for node in forecast: day = node.getAttribute('day') tod = node.getAttribute('tod')
# формируем массив, в котором лежат данные о погоде forecasts.append({ 'day': int(day), 'tod': int(tod), 'precipitation': int(precipitation), 'temp': temp, 'cloudiness': int(cloudiness), }) for forecast in forecasts[::-1]: day = u'Сегодня' if forecast['day'] == current_day.day else u'Завтра' if forecast['tod'] == 0: tod = u'ночью' elif forecast['tod'] == 1: tod = u'утром' elif forecast['tod'] == 2: tod = u'днем' elif forecast['tod'] == 3: tod = u'вечером' else: tod = '-'
class_<some_object_type>() .def("python_method_name", &some_object_type::c_method_name);
import QtQuick 2.3 import QtQuick.Window 2.2 import QtQuick.Controls 1.4 ApplicationWindow { id: window visible: true }
# -*- coding: utf-8 -*- import sys # noinspection PyUnresolvedReferences from PyQt5.QtCore import QUrl # noinspection PyUnresolvedReferences from PyQt5.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QPushButton # noinspection PyUnresolvedReferences from PyQt5.QtQuick import QQuickView class MyApp(QApplication): def __init__(self): super(MyApp, self).__init__(sys.argv) self.appLabel = QQuickView() self.appLabel.statusChanged.connect(self.on_status_changed) def on_status_changed(self,status): if status == QQuickView.Error: for err in self.appLabel.errors(): print (err.toString()) elif status == QQuickView.Ready: print('Status ready') else: print (status) def setSource(self, filename): self.appLabel.setSource(QUrl(filename)) def show(self): self.appLabel.show() # Main Function if __name__ == '__main__': # Create main app myApp = MyApp() # QApplication(sys.argv) # Create a label and set its properties myApp.setSource('mywindow.qml') # Show the Label myApp.show() # Execute the Application and Exit myApp.exec_() sys.exit()
a=[1,2,3,4,5,6,7,8,9] b=['a','b','c','d','e','f','g','h','x'] while len(a)!=1: zna= [b[0],b[1]] z=a[0]+a[1] a.append(z) a.sort() b.insert(a.index(z),zna) del a[1] del a[0] del b[1] del b[0] print(b) [[[['d', 'e'], 'x'], [[[['a', 'b'], 'c'], 'f'], ['g', 'h']]]]
from tkinter import * WIDTH = 900 #ширина HEIGHT = 300 #высота # по горизонтали BALL_X_CHANGE = 20 # по вертикали BALL_Y_CHANGE = 0 PAD_SPEED = 15 #скорость движения ракетки LEFT_PAD_SPEED = 0 #скорость левой ракетки RIGHT_PAD_SPEED = 0 #скорость правой ракетки INITIAL_SPEED = 20 BALL_MAX_SPEED = 40 # Начальная скорость по горизонтали BALL_X_SPEED = INITIAL_SPEED # Начальная скорость по вертикали BALL_Y_SPEED = 0 # Добавим глобальную переменную отвечающую за расстояние right_line_distance = WIDTH-30 # до правого края игрового поля root = Tk() c = Canvas(root,width=WIDTH,height=HEIGHT,background="#003300") #игровая область c.pack() c.create_line(WIDTH/2,0,WIDTH/2,HEIGHT,fill="white") #центральная линия c.create_line(30,0,30,HEIGHT,fill="white") #левая линия c.create_line(WIDTH-30,0,WIDTH-30,HEIGHT,fill="white") #правая линия BALL = c.create_oval(WIDTH/2-15,HEIGHT/2-15,WIDTH/2+15,HEIGHT/2+15,fill="white") #создаем мяч LEFT_PAD = c.create_line(15,0,15,100,width=30,fill="blue") #создаем левую ракетку RIGHT_PAD = c.create_line(WIDTH-15,0,WIDTH-15,100,width=30,fill="blue") #создаем правую ракетку def move_ball(): #функция движения мяча ball_left, ball_top, ball_right, ball_bot = c.coords(BALL) #получил координаты мяча ball_center = (ball_top + ball_bot) / 2 #нашел координату центра мяча if ball_right < right_line_distance and ball_left > 30: #проверяем не достиг ли шмяч границ поля, если нет то просто двигаем c.move(BALL, BALL_X_SPEED, BALL_Y_SPEED) elif ball_right == right_line_distance or ball_left == 30: #если шар достигает границ левого или правого полей то if ball_right > WIDTH/2: #проверяем находится ли он на правой стороне if c.coords(LEFT_PAD)[1] < ball_center < c.coords(LEFT_PAD)[3]: #проверяем находится ли мяч в пределах правой ракетки c.move(BALL,-BALL_X_SPEED,BALL_Y_SPEED) #то меняем скорость на противоположную def move_pads(): #функция движения ракеток c.move(LEFT_PAD, 0, LEFT_PAD_SPEED) if c.coords(LEFT_PAD)[1] < 0: c.move(LEFT_PAD, 0, -c.coords(LEFT_PAD)[1]) elif c.coords(LEFT_PAD)[3] > HEIGHT: c.move(LEFT_PAD, 0, HEIGHT-c.coords(LEFT_PAD)[3]) c.move(RIGHT_PAD, 0, RIGHT_PAD_SPEED) if c.coords(RIGHT_PAD)[1] < 0: c.move(RIGHT_PAD, 0, -c.coords(RIGHT_PAD)[1]) elif c.coords(RIGHT_PAD)[3] > HEIGHT: c.move(RIGHT_PAD, 0, HEIGHT-c.coords(RIGHT_PAD)[3]) def main(): move_ball() move_pads() root.after(30, main) c.focus_set() def movement_handler(event): #функция считывания нажатий клавиш global LEFT_PAD_SPEED,RIGHT_PAD_SPEED if event.keysym == 'w': LEFT_PAD_SPEED = -PAD_SPEED elif event.keysym == 's': LEFT_PAD_SPEED = PAD_SPEED elif event.keysym == 'Up': RIGHT_PAD_SPEED = -PAD_SPEED elif event.keysym == 'Down': RIGHT_PAD_SPEED = PAD_SPEED c.bind("<KeyPress>", movement_handler) def stop_pad(event): #функция считывания отпускания клавиш global RIGHT_PAD_SPEED,LEFT_PAD_SPEED if event.keysym == 'w': LEFT_PAD_SPEED = 0 elif event.keysym == 's': LEFT_PAD_SPEED = 0 elif event.keysym == 'Up': RIGHT_PAD_SPEED = 0 elif event.keysym == 'Down': RIGHT_PAD_SPEED = 0 c.bind("<KeyRelease>", stop_pad) main() root.mainloop()
client = Skype4Py.Skype() client.Attach() topic = unicode('Имя чата', 'utf-8') for chat in client.BookmarkedChats: if chat.Topic == topic: chat.SendMessage('текст!!!')
for chat in client.BookmarkedChats: print chat.Topic
import turtle wn = turtle.Screen() alex = turtle.Turtle() def drawRect(): alex.speed(0) alex.up() alex.fillcolor("green") alex.begin_fill() alex.setpos(-250, -100) alex.down() for i in range(2): alex.forward(500) alex.left(90) alex.forward(300) alex.left(90) alex.end_fill() drawRect() def drawLines(): alex.speed(0) alex.fillcolor("yellow") alex.begin_fill() alex.penup() alex.setpos(-250, 70) alex.pendown() for i in range(2): alex.forward(500) alex.left(90) alex.forward(30) alex.left(90) alex.end_fill() alex.fillcolor("black") alex.begin_fill() alex.penup() alex.setpos(-250, 40) alex.pendown() for i in range(2): alex.forward(500) alex.left(90) alex.forward(30) alex.left(90) alex.end_fill() alex.pencolor("white") alex.fillcolor("white") alex.begin_fill() alex.penup() alex.setpos(-250, 10) alex.pendown() for i in range(2): alex.forward(500) alex.left(90) alex.forward(30) alex.left(90) alex.end_fill() alex.speed(0) alex.fillcolor("yellow") alex.begin_fill() alex.penup() alex.setpos(-40, -100) alex.pendown() for i in range(2): alex.forward(30) alex.left(90) alex.forward(300) alex.left(90) alex.end_fill() alex.speed(0) alex.fillcolor("black") alex.begin_fill() alex.penup() alex.setpos(-10, -100) alex.pendown() for i in range(2): alex.forward(30) alex.left(90) alex.forward(300) alex.left(90) alex.end_fill() alex.speed(0) alex.pencolor("white") alex.fillcolor("white") alex.begin_fill() alex.penup() alex.setpos(20, -100) alex.pendown() for i in range(2): alex.forward(30) alex.left(90) alex.forward(300) alex.left(90) alex.end_fill() drawLines() def drawCircle(): alex.speed(0) alex.up() alex.setpos(10, -50) alex.down() alex.fillcolor("red") alex.begin_fill() alex.circle(100) alex.end_fill() drawCircle()
#! /usr/bin/env monkeyrunner import os from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice PACKAGE = 'com.android.browser' ACTIVITY = '.BrowserActivity' COMPONENT = PACKAGE + "/" + ACTIVITY URI = 'Нужный url device = MonkeyRunner.waitForConnection() device.startActivity(component=COMPONENT, uri=URI)