473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

RE Despair - help required

I am trying the following:

re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files")

and I get a return of NoneType, and I have no idea why. I know that I
missing something here, but I really can't figure out why (I bet it's
something obvious). I also tried this RE on KODOS and it works fine
there, so I am really puzzled.

Any ideas?
Thanks.
Aug 25 '05 #1
10 1238
Yoav enlightened us with:
I am trying the following:

re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files")

and I get a return of NoneType, and I have no idea why.
Because you don't match a carriage return "\r".
I know that I missing something here, but I really can't figure out
why (I bet it's something obvious).


Use forward slashes instead of backward slashes. And go nag at
Microsoft for using the most widely used escape character as a path
separator...

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Aug 25 '05 #2
Yoav wrote:
I am trying the following:

re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files")

and I get a return of NoneType, and I have no idea why. I know that I
missing something here, but I really can't figure out why (I bet it's
something obvious). I also tried this RE on KODOS and it works fine
there, so I am really puzzled.

Any ideas?


Look at the second string. It has "\r" in the middle of it where you
really want "\\r" (or alternatively r"c:\ret_files").

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Aug 25 '05 #3
Thanks guys. Issue solved.
I am also going to give Microsoft a call about it. Any other issues you
want me to raise while I am talking to them?
Cheers.

Robert Kern wrote:
Yoav wrote:
I am trying the following:

re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files")

and I get a return of NoneType, and I have no idea why. I know that I
missing something here, but I really can't figure out why (I bet it's
something obvious). I also tried this RE on KODOS and it works fine
there, so I am really puzzled.

Any ideas?

Look at the second string. It has "\r" in the middle of it where you
really want "\\r" (or alternatively r"c:\ret_files").

Aug 25 '05 #4
"Yoav" wrote:
I am trying the following:

re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files")

and I get a return of NoneType, and I have no idea why. I know that I
missing something here, but I really can't figure out why


instead of struggling with weird REs, why not use Python's standard
filename manipulation library instead?

http://docs.python.org/lib/module-os.path.html

</F>

Aug 25 '05 #5
Don't think it will do much good. I need to get them from a file and
extract the last folder in the path. For example:
if I get "c:\dos\util"
I want to extract the string "\util"

Fredrik Lundh wrote:
"Yoav" wrote:
I am trying the following:

re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files")

and I get a return of NoneType, and I have no idea why. I know that I
missing something here, but I really can't figure out why

instead of struggling with weird REs, why not use Python's standard
filename manipulation library instead?

http://docs.python.org/lib/module-os.path.html

</F>

Aug 25 '05 #6
Yoav wrote:
Don't think it will do much good. I need to get them from a file and
extract the last folder in the path. For example:
if I get "c:\dos\util"
I want to extract the string "\util"
like frederik says (I use '/' as I am using Unix):
import os
os.path.split ('c:/foo/bar') ('c:/foo', 'bar') os.path.splitext ('c:/foo/bar') ('c:/foo/bar', '') os.path.splitext ('c:/foo/bar.txt') ('c:/foo/bar', '.txt')

or if you are really reluctant:
'c:\\foo\\bar'.split ('\\') ['c:', 'foo', 'bar'] 'c:\\foo\\bar'.split ('\\') [-1]
'bar'

Fredrik Lundh wrote:

instead of struggling with weird REs, why not use Python's standard
filename manipulation library instead?

http://docs.python.org/lib/module-os.path.html

</F>

--
rafi

"Imagination is more important than knowledge."
(Albert Einstein)
Aug 25 '05 #7
Yoav wrote:
Don't think it will do much good. I need to get them from a file and
extract the last folder in the path. For example:
if I get "c:\dos\util"
I want to extract the string "\util"


Then os.path.basename should be for you.

Reinhold
Aug 25 '05 #8
Yoav wrote:
Don't think it will do much good. I need to get them from a file and
extract the last folder in the path. For example:
if I get "c:\dos\util"
I want to extract the string "\util"


You mean like this:

import os
os.path.sep + os.path.split(r"c:\dos\util")[-1]

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Aug 25 '05 #9
In article <43********@news.bezeqint.net>, Yoav <yo********@il.vio.com> wrote:
Fredrik Lundh wrote:
"Yoav" wrote:
I am trying the following:

re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files")

instead of struggling with weird REs, why not use Python's standard
filename manipulation library instead?

http://docs.python.org/lib/module-os.path.html

Don't think it will do much good. I need to get them from a file and
extract the last folder in the path. For example:
if I get "c:\dos\util"
I want to extract the string "\util"


Did you actually look at the docs Fredrik pointed you at? Did you,
in particular, notice os.path.basename, which does (almost) exactly
what you want?

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
Aug 25 '05 #10
Thank you all guys. It seems like the simpler the solution, the more I
am happy about it. Sorry, for the simple question, I am quite new to
this lang.

Cheers.

Robert Kern wrote:
Yoav wrote:
Don't think it will do much good. I need to get them from a file and
extract the last folder in the path. For example:
if I get "c:\dos\util"
I want to extract the string "\util"

You mean like this:

import os
os.path.sep + os.path.split(r"c:\dos\util")[-1]

Aug 25 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gregory (Grisha) Trubetskoy | last post by:
My humble $0.02: From http://www.python.org/doc/current/lib/optparse-terminology.html: The phrase "required option" is an oxymoron; the presence of "required options" in a program is usually a...
1
by: Bennett Haselton | last post by:
I want to get an ASP.Net hosting account with my ISP, and I'm trying to find out what level of access to the server is requried in order for me to view the server in Server Explorer in Visual...
5
by: Lorenzo Bolognini | last post by:
Hi all, i need to detect whether a field is required or not. I'm using this code for building a string to convert later to an array (by Split) of which each element matches the field index (ex....
6
by: yzzzzz | last post by:
Hi, In which cases is the <?xml version="1.0" encoding="UTF-8"?> processing instruction required at the beginning of an XML document, for the document to be valid? e.g. does it depend on the...
16
by: Georges Heinesch | last post by:
Hi. My form contains a control (cboFooBar), which has an underlying field with the "Required" property set to "Yes". Now, while filling out all the controls of the form, I have to fill out this...
2
by: bufbec1 | last post by:
I am pretty good with Access, but do not understand VBA. I have researched this topic and see only VBA answers, so I hope someone can help with my specific question. I have 2 fields for an...
3
by: Orchid | last post by:
Hello All, Hope someone can help me on my required field problems. I have a form base on a table for users to input new Employees. There are 4 fields that cannot be Null when entering new...
3
by: CindyRob | last post by:
I am using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, with hotfix 82202, Visual studio .NET 2003 with hotfix 823639. I have generated a proxy class using wsdl.exe from a schema that has an...
11
by: Naeem | last post by:
I have a Javascript function, which changes a text field of a form into a select field. Following is the function function changeStateField() { var myForm =...
1
by: KMEscherich | last post by:
Hi there, am wondering if there is a way to have this code capture 2 dates. You see, I have several fields and some are REQUIRED fields and some are NON-REQUIRED fields. I am attempting to capture...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.