expression « string « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » string » expression 

1. extracting a parenthesized Python expression from a string    stackoverflow.com

I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form ${expr}, for example, where ...

2. Problem with Boolean Expression with a string value from a lIst    stackoverflow.com

I have the following problem:

  # line is a line from a file that contains ["baa","beee","0"]
  line = TcsLine.split(",")
  NumPFCs = eval(line[2])
  if NumPFCs==0:
    ...

3. Sort a list of strings based on regular expression match or something similar    stackoverflow.com

I have a text file that looks a bit like:

random text random text, can be anything blabla %A blabla
random text random text, can be anything blabla %D blabla
random text random text, ...

4. How can I omit words in the middle of a regular expression in Python?    stackoverflow.com

I have a multi-line string like this:

"...Togo...Togo...Togo...ACTIVE..."
I want to get everything between the third 'Togo' and 'ACTIVE' and the remainder of the string. I am unable to create a regular expression ...

5. Evaluating a mathematical expression in a string    stackoverflow.com

stringExp = "2^4"
intVal = int(stringExp)      # Expected value: 16
This returns the following error:
Traceback (most recent call last):  
File "<stdin>", line 1, in <module>
ValueError: invalid literal ...

6. rreplace - How to replace the last occurence of an expression in a string    stackoverflow.com

Is there a quick way in Python to replace strings by starting from the end? For example:

>>> def rreplace(old, new, occurence)
>>>     ... # Code to replace the ...

7. Using Lambdas to build executable functions from string expressions    stackoverflow.com

I'm using python, and I want a function that takes a string containing a mathematical expression of one variable (x) and returns a function that evaluates that expression using lambdas. Syntax ...

8. Python: how to tell if a string represent a statement or an expression?    stackoverflow.com

I need to either call exec() or eval() based on an input string "s" If "s" was an expression, after calling eval() I want to print the result if the result was ...

9. how to retrieve field value (values are itself string)in given line using regular expression in python    stackoverflow.com

I am newbie to python,i am facing below issue please help me: I read line by line from one file, each line having field name and its value, now i have to ...

10. How to exclude comment lines when searching with regular expression?    stackoverflow.com

Need to exclude blocks that are located with a regular expression when preceded with # and any number of spaces. Here is a example file

&START   A=23  ... more ...

11. Python: String manipulation of type String substitution in mathematical expression    stackoverflow.com

Imagine something like

exp(49/200)+(x-49/200)
I want to pass as argument of the function "roundn" whatever operation that is not a addtion or a subtraction So my expresion became
roundn(exp(roundn(49/200,n)),n)+(x - roundn(49/200,n)
Well the expression I want ...

12. How to get the expression which has the maxium result in a string list?    stackoverflow.com

For example, I have a list a = ['3*4', '2*3', '4*6'], I want to print the string in the list whose result will be the largest, '4*6' in this case.

13. Why are these strings escaping from my regular expression in python?    stackoverflow.com

In my code, I load up an entire folder into a list and then try to get rid of every file in the list except the .mp3 files.

import os
import re
path = ...

14. string, regular expressions in python    stackoverflow.com

From the following question How to automatically remove certain preprocessors directives and comments from a C header-file?

header = "" #some string

p_macro = re.compile("#if.*?#endif", re.MULTILINE + re.DOTALL)  
p_comment = re.compile("/\*.*?\*/", re.MULTILINE ...

15. Python C API: why doesn't PyRun_String evaluate simple conditional expressions?    stackoverflow.com

PyRun_String("if True: 1\nelse: 0", Py_eval_input, globals, globals);
returns error with PyErr_Print() printing out:
File "<string>", line 1
  if True: 1
   ^
What am I doing wrong? Thank you.

16. Simplifying an Expression in Python    stackoverflow.com

I feel there must be a simpler/cleaner/faster (choose one or more) way to write this expression... take a BigString = "This is a long sentence about a red cat named dude." and LittleStringList ...

17. Searching for Regular Expressions in a string WITH overlap    bytes.com

I apologize in advance for the newbie question. I'm trying to figure out a way to find all of the occurrences of a regular expression in a string including the overlapping ones. For example, given the string 123456789 I'd like to use the RE ((2)|(4))[0-9]{3} to get the following matches: 2345 4567 Here's what I'm trying so far: #!/usr/bin/env python ...

18. String searching using a for loop and regular expressions    python-forum.org

String searching using a for loop and regular expressions by fireball73 Tue Mar 01, 2011 11:12 am Hello everyone, I am an astronomy student and I've been learning Python for a laboratory project involving the automation of a telescope. Part of which involves constructing an algorithim to search a database of astronomical objects. I have tried to do this two ...

19. Regular expression to extract a string between []    python-forum.org

Hi All, I am trying to extract a string using regular expression like this import re string = "[this is my string and can have anything here,even -] some/other/string" I want to get the value withing the square brackets which is part of the string itself result needed "this is my string and can have anything here,even -" This is how ...

20. regular expressions string manipulation    python-forum.org

Hello all, i am sure this is really simple but i am scratching my head trying to find out a way. I discover that using regular expressions is making my life easier because i am dealing with text manipulation. Let's suppose i have this line: " weight losses | weight loss | Weight loss | Weight Loss " 168.578313 "weight loss" ...

21. regular expression and UTF-8 strings    python-forum.org

According to the python docs there's something called the "Unicode character properties database", which tags unicode characters with information such as whether the character is considered alphanumeric. Either that database doesn't consider a 'LATIN SMALL LETTER A WITH ACUTE' to be alphanumeric, or python doesn't implement those tags correctly. Maybe the concept of alphanumeric isn't used in the unicode world? So...you ...

22. Converting regular expression into String    python-forum.org

Thank you all for your help. I'll try to explain what I would like to do. I would like to accomplish search using pattern compiled from GA[CG]{1}GA[CG]{1} and others elements of list which are pretty similar(using loop) to search into the same list. I decide to try make the list for searching as list of strings, and then searching is there ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.