Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.

Share tech news, updates, or what's on your mind.

Sign up to Post

I wanted to detect keyboard with pynput, so I copied and pasted a demo from their site. Here it is:

from pynput import keyboard

def on_press(key):
    try:
        print('alphanumeric key {0} pressed'.format(
            key.char))
    except AttributeError:
        print('special key {0} pressed'.format(
            key))

def on_release(key):
    print('{0} released'.format(
        key))
    if key == keyboard.Key.esc:
        # Stop listener
        return False

# Collect events until released
with keyboard.Listener(
        on_press=on_press,
        on_release=on_release) as listener:
    listener.join()
But I get this error, the file is named differently than the module:

Traceback (most recent call last):
  File "C:\Users\Andrey\Documents\Python\123.py", line 1, in <module>
    from pynput import keyboardFile
  "C:\Users\Andrey\AppData\Local\Programs\Python\Python36-32\pynput.py", line 10, in <module>
    with keyboard.Listener(NameError: name 'keyboard' is not defined
0
Cloud Class® Course: Amazon Web Services - Basic
LVL 12
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

I have a text file which has multiple attached words like RainyDay, PlayingInTheCold etc. These words can be split into normal forms using regex to make them into meaningful words.
import re, string, html
with open("1.txt", "r") as fin, open("2.txt", "w") as fout:
    for text in fin:
        words = text.split()
        cleaned = " ".join(re.findall('[A-Z][^A-Z]*', words))
        fout.write(cleaned)

Open in new window

error: error1Also, there are many slang words like helo, luv which should be converted to hello, love. I am trying like this
with open("1.txt", "r") as fin, open("2.txt", "w") as fout:
    for text in fin:
        words = text.split()
        words = slang_loopup(words)
        text = ' '.join(words)
        fout.write(cleaned)

Open in new window

I tried _slang_loopup() also but same NameError
error is: error2
Can someone please help me?
Thanks
0
Hi

In the abc module page, it describes using python abc's, and it seems very straightforward.  here

However, abc_base doesn't seem to work in my pycharm. From the text, it seems I must use a keyword called abc_base

It is underlined red in my Pycharm. How do I get it to work?

ChessPlayerBaseABC.py
RandomPlayer.py
ChessEngine.py

In RandomPlayer, My code should work. - attached above, at least abc_base should not be underlined red, as the text example page uses abc_base
What is wrong?
Thanks
0
Hello Experts,

I'm just getting started learning SQL and Python.

Compiling sql queries and python queries is pretty tough going.

I was wondering if someone could let me know if there are any GUI tools out there they could recommend to help write sql and python queries?

Thanks

Carlton
0
How to extract postcode out of the string?
example: how to extract "D18 W528"
from this string "20 Corbawn Close Dublin 18 D18 W528" in csv file
0
When using Python, I am able to type  my code into a file using the IDLE editor, save the file and and run the program without any problems.  My output is displayed in the shell. However, when I try to do the same  thing with the turtle graphics, I keep getting an error. For example, I typed the following code into a file to draw a square.

import turtle
t = turtle.Pen()
t.forward(50)
t.left(90)
t.forward(50)
t.left(90)
t.forward(50)
t.left(90)

However, when I tried to run my program, I get the following error:

Traceback (most recent call last):
  File "C:/Users/hdtest/Desktop/turtle.py", line 1, in <module>
    import turtle
  File "C:/Users/hdtest/Desktop\turtle.py", line 2, in <module>
    t= turtle.Pen()
AttributeError: module 'turtle' has no attribute 'Pen'

It seems like it will only work within the shell itself, i.e., interactively.

How can I get it to run as a program?
0
Class and method: main() in python

I have seen examples in python where they use class main() or method main(). I wonder if it has the same meaning as in Java, where the main method gets executed first, or it is just a name that can be different than main() ?

Thank you
0
Python forms for Database programming.

In other programming languages, programmers use forms to drop labels, buttons, textboxes, drop down arrows,etc....they also create links to the database from the form.
programmers will write code for the Events created, for instance when user click on a button, or tabs to another textbox,etc....
I wonder what type of forms that Python use to achieve similar goal.

Thank you
0
how to delete those lines in a text file having only 1 word like #test or any1word like amaze. I want to keep those lines having words more than 1 like amazing python
0
https://www.experts-exchange.com/questions/29106263/replacing-hypertext-links-with-simple-text-'URL'.html#a42605453

I need to remove all http starting from http:\/
I am able to remove all http starting from http://  and the regular expression for this is given in the above link.

url_rex = re.compile(r'(http|ftp|https)://[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?')

How can I modify this regular expression remove http starting from http:\/

Also, the below code deletes the characters @, # from the words starting from @ or # which I intend to keep.

import re, string, html
uni_escape = re.compile(r'\\u[0-9a-f]{4}')
url_rex = re.compile(r'(http|ftp|https)://[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?')
with open("input.txt", "r") as fin, open("output.txt", "w") as fout:
    for text in fin:
		unesc_html_text = html.unescape(text)
		encoded_text = bytes(unesc_html_text, 'ascii', errors='ignore')
		decoded_ascii_text = encoded_text.decode('ascii')
		unesc_text = re.sub(uni_escape, '', decoded_ascii_text)
		text = url_rex.sub('', unesc_text)
		fout.write(text)

Open in new window


How to change the regular expression to keep @ and # in words?
0
Upgrade your Question Security!
LVL 12
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Python Class classname (Object)

I have the codes below if I declare the class Car(object) or just class Car, I get the same result. I am not sure what the keyword (Object) is for.

Thanks


class Car:

    wheels = 4

    def __init__(self, make, model):
        self.make = make
        self.model = model

mustang = Car('Ford', 'Mustang')
print (mustang.wheels)
# 4
print (Car.wheels)
# 4
0
Hi,
I have added python plugin to my Intellij Idea
I can command click on any function that i am using and go to the source file that is a python built in library. But i only see the definition of the function there and not the code.. (python_stubs)
how can i download and add the source code to the python built in libraries and see them inside Intellij Idea.

Thanks
0
I am iterating over rows in pandas with itertools.

for index, row in df.iterrows():
    print(row['firstname'])

It will print the firstname of each row. Now I want to compare these names to see if they are equal.
0
Hi,
I am running python on Intellij IDEA  community 2018.1
Have installed the python community Edition
On the page - https://www.jetbrains.com/help/idea/matplotlib-tutorial.html
I see they mention View-Scientific Mode
But doesnt show up in my Intellij Idea
What could be the reason for that ?

Thank
0
i have a one to many relationship in Flask SQLAlchemy and it works fine.

Imagine it as Student and Class.

I would like to add constraint so that if I add a student without a class it doesn't work and I know I can do this using nullable=False.

How can I make it so that even if I add a student with a NON existing class I get an error?

Example:
Student 1 is in class 5 but class 5 doesn't exist in classes table.
0
Python is Interpreter or Compiler based language

I have read that Python is an Interpreter based language. Does that mean it can be slow to render the results when it is run ?

Thank you
0
Hi All,

I am completely new to python. I would like to know how to find out what modules are available and what i can do with those modules

for example -

import os
import win32serviceutil

how would i find out the functions, etc that are available in the win32serviceutil?

hope this makes sense
0
Hi
I'd like to install tkinter in my Pycharm

I go to preferences and hit the + install button and there are a chunk of tkinter installs to consider.

Does it matter which one I choose?

Thanks
0
I have a data set containing duplicates values in rows for multiple columns. I am looking to do row wise matching of values for 2 or 3 columns.
0
Get your problem seen by more experts
LVL 12
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Hi,when I created a StaticBitmap, and a combobox. I had the idea that, as I would to change the image in StaticBitmap, from another event.
From combobox.

my code of StaticBitmap
self.m_bitmap1 = wx.StaticBitmap(self, wx.ID_LOGO, wx.Bitmap(u"example.png", wx.BITMAP_TYPE_ANY),
                                         wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_bitmap1.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_ACTIVEBORDER))
        self.m_bitmap1.SetToolTip(u"logo of example")
        bSizer6.Add(self.m_bitmap1, 0, wx.ALIGN_CENTER | wx.ALL, 5)

Open in new window


event of combobox
def option_combo(self, event):
    selection = self.comboBox_Dir.GetSelection()
    if selection == 0:
        pass      # change image in StaticBitmap
 
 
    #print(selection)
    #event.Skip()

Open in new window

0
I'm trying to get my IDE to run Python Programs on Ubuntu Desktop 18.04.

I installed the Pycharm Community edition and after that I typed out a hello world program

print('Hello, World!')

Open in new window


When I run the code I get the following error

/home/brian/PycharmProjects/hello/venv/bin/python /usr/bin/python3.6 /home/brian/PycharmProjects/hello/hello.py
  File "/usr/bin/python3.6", line 1
SyntaxError: Non-UTF-8 code starting with '\x9c' in file /usr/bin/python3.6 on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Process finished with exit code 1


I think I tied in the interpretor correctly because it is actually giving me an error.

Googled to no avail so figured to ask a really stupid question.
0
I want to create my first application (I'm a web dev) in Python.

I'm going to try and create an open source version of Neck Diagrams (neckdiagrams.com). If that is beyond me I'll come back to it soon.

So I need to learn Python and GUI programming in Python.

I was hoping some people could recommend books to learn Python and books to learn GUI Programming in Python.
0
I am using Python pymysql to insert rows into an empty MySQL table.  I tried doing this row by row and using executemany  method.  It takes over a minute to insert just a little over 2000 rows.  What can be done to speed this up?

>
            with connection.cursor() as cursor:
                cursor.executemany(sql, rows)
0
When working with Python and MySQL on Linux or Mac , what is the right strategy not to have mysql user password in the Python script?
0
Attempting to gather historical performance statistics from a Fujitsu Eternus DX 600 storage unit, such as IOPS and bandwidth through the FC ports.

Tried using Eternus SF Express, installs fine but there is zero documentation on what the default login is, could not proceed.
Tried using Nagios and the Fujitsu plugin file for Nagios, plugin fails to load due to errors in the python 2.7 script
Tried using SNMP traps but all I get on the SNMP is errors such as 'NoSuchName'

Suggestions on the best way to gather the stats I require?
0

Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.