Tag Info

New answers tagged

0

You could use the Gtk.TreeSelection.set_select_function functionality for this. Basically you give it a function, each time a row is selected this function is called. When it returns False the row can't be selected. Here's an example: treeview = builder.get_object("treeview3") selection = treeview.get_selection() selection.set_select_function(_select_func, ...


2

Ok, I've found what was missing. Here you can find in one answer, that in all the requirements are actually these ones: sudo apt-get install -y libxml2-dev libxslt1-dev zlib1g-dev python3-pip After that, you can safely do sudo pip install lxml


1

Ubuntu has Python 2.7 set as default. So, running python or pip normally runs the 2.7 version. If you want to run version 3 then you have to use the command python3 and pip3 pip3 -V python3 -V For the virtual envirmoment if found the command pyvenv-3.4 pyvenv-3.4 myenv_folder #Creates a python 3.4 virtual enviroment in the myenv_folder cd myenv_folder ...


0

Open a python shell and type: import sys sys.path /usr/local should normally be first, so it will be searched first.


1

The "Python.h" error message indicates that you are missing the python3-devpackage, which you need to build any Python extensions (Python modules written in C), which you can get with: apt-get install python3-dev To get up and running from scratch: apt-get update && apt-get install python3-dev python3-pip build-essential libzmq3-dev pip3 install ...


1

awk seems to be the easiest to use for this problem: $ echo "blahŤfoobar1Ťblah" | awk -FŤ '{ print $2 }' foobar1


1

Using bash : $ test='blahŤfoobar1Ťblah' $ spamegg="${test#*Ť}" $ echo "${spamegg%Ť*}" foobar1 Here we have used the bash parameter expansion get the desired substring. "${test#*Ť}" will remove the portion blahŤ , so the variable spamegg will have foobar1Ťblah ${spamegg%Ť*} will remove the trailing Ťblah, so we would get the output foobar1 Using grep : ...


0

You can also use perl to extract the text: $ echo 'blahŤfoobar1Ťblah' | perl -FŤ -ane 'print"$F[1]\n"' foobar1 Here the key is to use the -F option to set the delimiter. Another approach using a regular expression: $ echo "blahŤfoobar1Ťblah" | perl -pe 's/.*Ť(.*)Ť.*/$1/' foobar1


0

awk likes these things: $ awk -F"Ť" '{print $2}' <<< "blahŤfoobar1Ťblah" foobar1 By using Ť as field separator, we make sure we catch the desired text in the second block. If we would like to skip the processing if no Ť is found in a given line, we could use awk -F"Ť" 'NF>1{print $2}'. Regarding your attempt not working: by saying sed -n ...


1

Using sed echo "blahŤfoobar1Ťblah" | sed -e 's/\(^.*Ť\)\(.*\)\(Ť.*$\)/\2/' output foobar1 Another possible way using sed echo "blahŤfoobar1Ťblah" | sed 's/.*Ť\(.*\)Ť.*/\1/' output foobar1


7

You can use a cut command. To extract the second pattern: echo "blah@foobar1@blah" | cut -f2 -d"@" To extract the second and third patterns: echo "blah@foobar1@blah" | cut -f2,3 -d"@" To extract from the second pattern onwards echo "blah@foobar1@blah" | cut -f2- -d"@" EDIT: Since the question was tagged with awk. Here is an awk solution. echo ...


1

Add the path ~/.local/bin to the PATH environment. Open the file .bashrc in a terminal nano ~/.bashrc and add :$HOME/.local/bin at the end of the PATH definition e.g. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$HOME/bin:$HOME/.local/bin and add the line: alias my_app="scdl - l <link>" to start your ...


1

The steps that worked for me: On MAC OSX 10.9.5 1. Download and install Python-3.4 manually. cd /Users/<userid>/Python3/Python3.4 tar -zxvf Python-3.4.3.tgz ./configure --prefix=/Users/bdastur/Python3/Python-3.4.3 make; make install Create a virtualenv. /Users/bdastur/Python3/Python-3.4.3/bin/pyvenv py3env source py3env/bin/activate Note ...


1

Without python-openbabel: % python Python 2.7.9 (default, Apr 2 2015, 15:33:21) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import openbabel Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named openbabel >>> % python Python ...


0

Install it using pip sudo pip install colorama If you don't have pip read How to install pip for python 3 in ubuntu 12.04 LTS Another way is to download colorama module from here. Now extract the package cd colorama* Then run python setup.py install


0

Try running sudo apt-get install python-wxversion.


0

Look inside the bin folder of the pycharm folder you extracted. There are files called pycharm64.vmoptions and pycharm.vmoptions. Inside them, you can delete the line with the culprit option of MaxPermSize=350m.


0

Open the file pycharm64.vmoptions nano /opt/pycharm-community-4.5/bin/pycharm64.vmoptions and add a # at the beginning of the line # -XX:MaxPermSize=350m Open the file pycharm.vmoptions nano /opt/pycharm-community-4.5/bin/pycharm.vmoptions and add a # at the beginning of the line # -XX:MaxPermSize=250m MaxPermSize support was removed in Java ...


1

Solution After googling for answers since yesterday, I came across no way to set the default pip. I decided to go through and remove every instance of pip I could discover. sudo -H pip3 uninstall pip sudo -H pip2 uninstall pip sudo apt-get purge -y python-pip # It should be noted, 'python-pip' is the ubuntu package for pip2, but # there is also another ...


1

I figured out how to do it! After some research, I figured out the following would work: 1. Import system processes from multiprocessing import Process import subprocess this need to be added at the top of AppNameWindow.py. 2. Connect a button to an application def on_button1_clicked(self, widget, data=None): p = Process(target=self.launch_gcc) ...


1

Install the package inoticoming sudo apt-get install inoticoming Create wrapper script watch_output: #!/bin/bash backup_folder="$HOME/backups" filename="$1" mkdir -p "$backup_folder" if [ "$filename" == "output.txt" ] then echo "New or changed file \"output.txt\" in $2" mv "$2/$filename" "$backup_folder/${filename%.*}.$(date ...


3

First install the package inotify-tools: sudo apt-get install inotify-tools A bash script would help #! /bin/bash folder=~/Desktop/abc cdate=$(date +"%Y-%m-%d-%H:%M") inotifywait -m -q -e create -r --format '%:e %w%f' $folder | while read file do mv ~/Desktop/abc/output.txt ~/Desktop/Old_abc/${cdate}-output.txt done What does this script ...


2

The script below will move and rename any file that might appear in a defined directory (dr1). It renames the files like: output_1.txt, output_2.txt` etc. The script looks "actively" if the targeted name already exists in directory 2 (not from a "blindly" chosen range), so you can start and stop the script at any time without the risk of overwriting existing ...


1

Since VTE 0.38, vte_terminal_fork_command_full () has been renamed to vte_terminal_spawn_sync (). So if you are using newer versions, you have to change @ADcomp's answer into the following: terminal.spawn_sync( Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"], [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None, )


0

Finally The best is to write cd and the whole path. with the use of the upper array in terminal, it is easy to write again the path. The use of control + B in sublime is less practical, in particular for input() functions. and in the terminal it is easy for the choice of python version, 2.7 or 3.4. for ruby too.


0

Move the folder /home/marius/.python-eggs/ with mv /home/marius/.python-eggs /home/marius/.python-eggs.bak and install acestream again from this repository: sudo apt-add-repository "deb http://repo.acestream.org/ubuntu/ trusty main" sudo wget -O - http://repo.acestream.org/keys/acestream.public.key | sudo apt-key add - sudo apt-get update sudo apt-get ...


1

python solution using re module and considering two situations : #!/usr/bin/env python2 import re with open('/path/to/file.txt') as f: for line in f: digits_case_1 = re.search(r'(?<=^\[)\d+(?=\])', line) digits_case_2 = re.search(r'(?<=^\[)\d+(?=\].*\);$)', line) if digits_case_1: print 'Not considering ");" at ...


0

cat $FILE | awk -F\] '{ print $1 }' | grep '\[' | tr -d '[' Where the progression is:§ $ FILE=/tmp/tmp.tmp $ cat $FILE [581]((((((((501:0.00024264,451:0.00024264):0.000316197,310:0.000558837):0.00857295,((589:0.000409158,538:0.000409158):0.000658084,207:0.00106724 ...


4

the perl way: perl -ne 'print "$1\n" if /^\[([0-9]*)\].*/' testdata > out or with awk: awk 'match($0, /^\[[0-9]*\]/) {print substr($0, RSTART + 1, RLENGTH - 2)}' testdata > out Used Regex in both cases: ^\[[0-9]*\] Explanation /^\[[0-9]*\]/ ^ assert position at start of the string \[ matches the character [ literally [0-9]* match a ...


11

You can achieve this with just a single grep command. This is because GNU grep lets you use a Perl regular expression (-P), which supports zero-width lookaround assertions (\K and (?= ), in this case): grep -oP '^\[\K\d+(?=\])' infile As written, that will send the output to your terminal. To redirect it to a file, use: grep -oP '^\[\K\d+(?=\])' infile ...


8

Using sed: < inputfile sed -n 's/^\[\([0-9]*\)\].*$/\1/p' > out Command breakdown: < inputfile: redirects the content of inputfile to stdin -n: suppresses output > out: redirects the content of stdout to out Regex breakdown: s: performs a substitution /: starts the regex ^: matches the start of the line \[: matches a [ character \(: ...


2

Use this in Bash: grep -oh '\[[0-9].*\]' mytestfile | sed 's/.*\[\([^]]*\)\].*/\1/g' > myresultfile


1

The perl way: #!/usr/bin/perl $filename=$ARGV[0]; open(my $fh, "<", $filename) or die "cannot open < $filename: $!"; my %hash, my $key; while (my $row = <$fh>) { chomp $row; if ($row =~ /\-bar\s+([0-9]+)/ ) { $key = $1; } $hash{$key} .= "$row\n"; } foreach (sort { $a <=> $b } keys(%hash) ) {print "$hash{$_}"} Save the ...


0

SimpleHTTPServer by default binds to the ip address 0.0.0.0. This is a special address meaning in effect "any address". If it were to bind to for example localhost or 127.0.0.1, you could only connect to it from the local machine, because 127.0.0.1 belongs to the loopback device. But with 0.0.0.0, the server's binding to lo, eth0 and any other network ...


1

Using python: #!/usr/bin/env python2 import re, sys list_of_lines = [] with open(sys.argv[1]) as f: for line in f.read().split('-foo'): if line: list_of_lines.append(line) for line in sorted(list_of_lines, key=lambda i: int(re.search(r'(?<=-bar )\d+', i).group())): print '-foo' + line.rstrip() Output : -foo -bar 1 \ ...


0

The solution was to manually uninstall the package as described here: To manually uninstall the broken package run the two commands below as root in Debian, preceded by sudo in Ubuntu : mv /var/lib/dpkg/info/PACKAGE.* /tmp/ dpkg --remove --force-remove-reinstreq PACKAGE where PACKAGE is the broken package


2

You need to loop the array and call worksheet.write for each item. You have to specify which row/column you're writing to so we can use the builtin enumerate to count out each item in the array. You want something like this: for i, fintitem in enumerate(fint, start=1): worksheet.write(globdat.cycle, i, fintitem)


1

PHP would be: if (preg_match_all('/"(?:[^"\\\\]+|\\\\.)+"|\\([^)]+\\)/', $input, $matches)) { echo implode(' ', $matches[0]); } This also correctly handles escaped characters inside quoted strings (eg "Test \"string\"" is treated as one string.


2

Below simple python code will do this job. import re with open('file') as f: reg = re.compile(r'"[^"]*"|\([^)]*\)') for line in f: print(' '.join(reg.findall(line))) And another one through Perl which uses only regex, $ perl -pe 's/(?:"[^"]*"|\([^)]*\))(*SKIP)(*F)|\S//g;s/^\h+|\h+$|(\h)+/\1/g' file "foo foo" (bar bar) (19) "foo foo"


2

Another perl: $ perl -nle 'print join " ", $_ =~ /".*?"|\(.*?\)/g' file "foo foo" (bar bar) (19) "foo foo"


3

Ubuntu Touch only ships with Python 3. The module SimpleHTTPServer is one of the modules that has been renamed and/or moved for more consistency in the standard library. That said, you can run the following command: python3 -m http.server I can't guarentee this will work on Ubuntu Touch though, this is just the normal way to do it.


3

If you (or someone else with a similar problem who reads this) don't need to preserve the newlines, the following would work: grep -Eo '"[^"]*"|\([^)]*\)' For input 19. "foo foo" (bar bar) (19) raboof "foo foo" raboof it yields output "foo foo" (bar bar) (19) "foo foo" If you need newlines, you can use some tricks, e.g. this: sed 's/$/\$/' \ | grep ...


3

As perl script: $filename=$ARGV[0]; if (open(my $fh, '<:encoding(UTF-8)', $filename)) { while (my $match = <$fh>) { while ($match =~ /((\(.*?[^)]\))|(".*?"))/g) { print "$1 "; } print "\n" } } Or as perl one-liner: perl -ne 'while (/((\(.*?[^)]\))|(".*?"))/g) {print "$1 ";} print "\n"' file Output "foo foo" (bar bar) ...


5

New version (spaces allowed between () or ""): Try the below perl command (credits: @steeldriver) perl -ne 'printf "%s\n", join(" " , $_ =~ /["(].*?[)"]/g)' Initial version (no spaces between () or "") You can try the following perl oneliner: $ perl -ne '@a=split(/\s+/, $_); for (@a) {print "$_ " if /[("].*?[)"]/ };print"\n"' file


4

Another python option: #!/usr/bin/env python3 import sys match = lambda ch1, ch2, w: all([w.startswith(ch1), w.endswith(ch2)]) for l in open(sys.argv[1]).read().splitlines(): matches = [w for w in l.split() if any([match("(", ")", w), match('"', '"', w)])] print((" ").join(matches)) Copy the script into an empty file, save the script as ...


9

Using python: #!/usr/bin/env python2 import re, sys with open(sys.argv[1]) as f: for line in f: parts = line.split() for i in parts: if re.search(r'^[("].*[)"]$', i): print i, print '\n'.lstrip() Output: "foo" (bar) (19) "foo" Every line is read and parts separated by spaces are saved into a ...


0

You can use notify-send as an external command: import subprocess as s s.call(['notify-send','foo','bar']) Or you can use the notify2 module (sudo apt install python3-notify2): import notify2 notify2.init('foo') n = notify2.Notification('foo', 'bar') n.show() There are more examples included in the package (see ...


1

You're probably looking for Anjuta. It's an IDE with Glade built in.


0

Yes, there is. :) Rather different from PyCharm, but Stani's Python Editor is a great IDE for Python and ships with wxGlade (among other useful tools such as Kiki). It can be installed from Ubuntu repositories with: sudo apt-get install spe


0

Quickly uses Glade as GUI designer. You can use Glade with PyCharm, too.



Top 50 recent answers are included