Eval and raw string ?? | Bytes (2024)

Home Posts Topics Members FAQ

Mark

Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tkll l\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3 >", line 1, in <module>
eval("r'C:\tkll l\ndfd\bll'")
File "<string>", line 1
r'C:klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

Thanks in advance,
Mark

Aug 22 '07 #1

Subscribe Reply

4 Eval and raw string ?? | Bytes (1) 2085 Eval and raw string ?? | Bytes (2)

Frederick Polgardy

On Aug 22, 11:06 am, Mark <cree...@gmail. comwrote:

Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tkll l\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3 >", line 1, in <module>
eval("r'C:\tkll l\ndfd\bll'")
File "<string>", line 1
r'C: klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

Thanks in advance,
Mark

The r'' format is purely for the interpreter; eval wouldn't know the
difference.

Your problem is that eval and exec evaluate source. You're trying to
do execfile().

Fred

Aug 22 '07 #2

Peter Otten

Mark wrote:

Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tkll l\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3 >", line 1, in <module>
eval("r'C:\tkll l\ndfd\bll'")
File "<string>", line 1
r'C: klll
^
SyntaxError: EOL while scanning single-quoted string

The string you are passing to eval already contains that newline. Use a raw
string instead:

>>eval(r"r'C:\t klll\ndfd\bll'" )

'C:\\tklll\\ndf d\\bll'

Peter

Aug 22 '07 #3

Paul McGuire

On Aug 22, 11:06 am, Mark <cree...@gmail. comwrote:

Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tkll l\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3 >", line 1, in <module>
eval("r'C:\tkll l\ndfd\bll'")
File "<string>", line 1
r'C: klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

Thanks in advance,
Mark

This is not a raw string: "r'\tsometh ing in quotes'". It is a string
starting with an "r", a "'", a tab, and and "s".

This is a raw string: r'\tsomething in quotes'. It is a string
starting with a "\", a "t" and an "s".

Notice that the \t and \n in c:\tkllll\ndfd\ bll were treated like tab
and newline? Try eval(r'c:\tklll l\ndfd\bll')

(You will get a different error now, but it wont be a raw string
problem.)

-- Paul

Aug 22 '07 #4

Matthew Woodcraft

Mark <cr*****@gmail. comwrote:

Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tkll l\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3 >", line 1, in <module>
eval("r'C:\tkll l\ndfd\bll'")
File "<string>", line 1
r'C:klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

The \n is being converted to a newline before the string is passed to eval.

Try eval(r"r'C:\tkl ll\ndfd\bll'")

-M-

Aug 22 '07 #5

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

Similar topics

7 4096

Why is 'eval' evil?

by: Reply Via Newsgroup |last post by:

This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed the script and special attention was thrown at the fact the script used eval alot. I don't use eval alot in my scripts - but I do use it - and...

Javascript

11 1866

Sorry... another question about eval()

by: sneill |last post by:

I have read a number of posts on the use of eval() in Javascript, and I agree that its use is questionable. But it does beg the following question: "How arbitrary does a string need to be before the use of eval() is required to execute it?" Given the following code, I'm able to evaluate/execute most expressions like: "a.b.c.d()"

Javascript

3808

DataBinder.Eval Error!

by: Michelle Keys |last post by:

Subject: DataBinder.Eval Error! Server Error in '/MSPOS' Application. ------------------------------------------------------------------------ -------- DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name REPORTTO. Description: An unhandled exception occurred during the execution of the

C# / C Sharp

18 3147

Eval code and AppDomains

by: Joe Fallon |last post by:

I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the...

ASP.NET

24 3409

Is Eval Evil for Ajax Responses

by: Larry |last post by:

Hi there: I have seen numerous postings about eval() and its evils on this forum. However, one of our developers is using it in the following way, which seems like a great use of it. Page makes Ajax request to ASP.Net web service. Web service does some data lookup and builds a string representation of a Javascript array which is then...

Javascript

15 3649

eval to dict problems NEWB going crazy !

by: manstey |last post by:

Hi, I have a text file called a.txt: # comments I read it using this:

Python

3 1900

eval problem

by: Pauljh |last post by:

Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do arrays each select is individually named withe MySelecti where i is an incremental from 1. I know all my variables are correct (i, OptionsCount)...

Javascript

1150

eval raising SyntaxError (was No Subject)

by: J. Clifford Dyer |last post by:

On Tue, 2007-12-11 at 16:55 -0800, katie smith wrote: Katie, First, please provide a useful subject heading when posting to the list. It makes everyone's life easier when searching the archives. Second, the example you provided in your last post was converting a string of the form "" to a list of integers. What is happening here, is...

Python

16 3917

eval() == evil? --- How to use it safely?

by: Fett |last post by:

I am creating a program that requires some data that must be kept up to date. What I plan is to put this data up on a web-site then have the program periodically pull the data off the web-site. My problem is that when I pull the data (currently stored as a dictionary on the site) off the site, it is a string, I can use eval() to make that...

Python

974

Re: eval() == evil? --- How to use it safely?

by: Jean-Paul Calderone |last post by:

On Thu, 28 Aug 2008 14:51:57 -0700 (PDT), Fett <fettmanchu@gmail.comwrote: eval and exec are the same. Don't use either with strings from a web page. Try using a simple format for you data, such as CSV. Jean-Paul

Python

7841

What is ONU?

by: marktang |last post by:

ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...

General

8105

Problem With Comparison Operator <=> in G++

by: Oralloy |last post by:

Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...

C / C++

8272

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

by: jinu1996 |last post by:

In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...

Online Marketing

8137

Discussion: How does Zigbee compare with other wireless protocols in smart home applications?

by: tracyyun |last post by:

Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...

General

5336

Couldn’t get equations in html when convert word .docx file to html file in C#.

by: conductexam |last post by:

I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...

C# / C Sharp

3774

Trying to create a lan-to-lan vpn between two differents networks

by: TSSRALBI |last post by:

Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

Networking - Hardware / Configuration

3793

Windows Forms - .Net 8.0

by: adsilva |last post by:

A Windows Forms form does not have the event Unload, like VB6. What one acts like?

Visual Basic .NET

1 2274

transfer the data from one system to another through ip address

by: 6302768590 |last post by:

Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

C# / C Sharp

1101

Comprehensive Guide to Website Development in Toronto: Expert Insights from BSMN Consultancy

by: bsmnconsultancy |last post by:

In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

General

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

To disable or enable advertisem*nts and analytics tracking please visit the page.

Eval and raw string ?? | Bytes (2024)

References

Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 5707

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.