473,847 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List problems in C code ported to Python

I'm done porting the C code, but now when running the script I
continually run into problems with lists. I tried appending and
extending the lists, but with no avail. Any help is much appreciated
Please see both the Python and C code at
http://home.earthlink.net/~lvraab. The two files are ENIGMA.C and engima.py

TIA
Jul 18 '05 #1
20 2246
Lucas Raab wrote:
Please see both the Python and C code at
http://home.earthlink.net/~lvraab. The two files are ENIGMA.C and engima.py


If you post a small testcase here you are much more likely to get helped.
--
Michael Hoffman
Jul 18 '05 #2
On 2005-01-16, Lucas Raab <py*********@ho tmail.com> wrote:
I'm done porting the C code, but now when running the script I
continually run into problems with lists. I tried appending and
extending the lists, but with no avail. Any help is much appreciated
Please see both the Python and C code at
http://home.earthlink.net/~lvraab. The two files are ENIGMA.C and engima.py


http://www.catb.org/~esr/faqs/smart-questions.html

--
Grant Edwards grante Yow! Did an Italian CRANE
at OPERATOR just experience
visi.com uninhibited sensations in
a MALIBU HOT TUB?
Jul 18 '05 #3
Grant Edwards wrote:
On 2005-01-16, Lucas Raab <py*********@ho tmail.com> wrote:
I'm done porting the C code, but now when running the script I
continually run into problems with lists. I tried appending and
extending the lists, but with no avail. Any help is much appreciated
Please see both the Python and C code at
http://home.earthlink.net/~lvraab. The two files are ENIGMA.C and engima.py

http://www.catb.org/~esr/faqs/smart-questions.html


I didn't expect to get bitched out just because I didn't follow "protocol."
Jul 18 '05 #4
"Lucas Raab" <py*********@ho tmail.com> wrote in message
news:vr******** ******@newsread 3.news.atl.eart hlink.net...
I'm done porting the C code, but now when running the script I
continually run into problems with lists. I tried appending and
extending the lists, but with no avail. Any help is much appreciated
Please see both the Python and C code at
http://home.earthlink.net/~lvraab. The two files are ENIGMA.C and engima.py
TIA


I didn't actually run your script, but you have some fundamental things to
fix first. Here are some corrections that will get you closer:

- Single-character strings are still strings as far as Python is concerned.
Unlike C's distinction of single quotes for single characters (which allow
you to do integer arithmetic) and double quotes for string literals (which
don't support integer arithmetic), Python uses either quoting style for
strings. So "A" == 'a' is true in Python, not true in C. To do single-char
arithmetic, you'll need the ord() and asc() functions, so that instead of
c-'A'
you'll need
ord(c)-ord('A')
(and another little tip - since the ord('A') is likely to be invariant, and
used *heavily* in a function such as an Enigma simulator, you're best off
evaluating it once and stuffing it into a global, with an unimaginitive name
like ord_A = ord('A')

-Line 42: You are testing c == string.alpha_le tters, when I think you
*really* want to test c in string.alpha_le tters.

- encipher_file - the C version of this actually reads the file and calls
encipher() with each character in it. Your Python version just calls
encipher() with the complete file contents, which is certain to fail.
(another tip - avoid variable names like 'file', 'string', 'list', 'dict',
etc. as these collide with global typenames - also, your variable naming is
pretty poor, using "file" to represent the filename, and "filename" to
represent the file contents - err???)

- usage() - print("blahblah \n") - the trailing \n is unnecessary unless you
want to double-space your text

Although you say you are "done porting the C code", you really have quite a
bit left to do yet. You should really try to port this code a step at a
time - open a file, read its contents, iterate through the contents, call a
method, etc. "Big-bang" porting like this is terribly inefficient!

-- Paul
Jul 18 '05 #5
"Paul McGuire" <pt***@austin.r r._bogus_.com> wrote:
"A" == 'a' is true in Python, not true in C.


It could be true in C, if the string is stored in very low memory :-)
Jul 18 '05 #6
Paul McGuire wrote:
So "A" == 'a' is true in Python, not true in C.

"A" == 'a' False

I think you meant:
"A" == "A"

True
--
Michael Hoffman
Jul 18 '05 #7
Paul McGuire wrote:
So "A" == 'a' is true in Python, not true in C.


It's not true in Python either.
You probably meant to say: "a" == 'a'
(lowercase a)

--Irmen
Jul 18 '05 #8
Lucas Raab wrote:
Grant Edwards wrote:
http://www.catb.org/~esr/faqs/smart-questions.html


I didn't expect to get bitched out just because I didn't follow "protocol."


I didn't see anyone bitch you out. And you were lucky that one
person was kind enough to go through your web site and make some
suggestions. If you had written a better question I guarantee you would
have had more people answering your question sooner.

Oh yeah, and:

http://www.catb.org/~esr/faqs/smart-...tml#not_losing
--
Michael Hoffman
Jul 18 '05 #9
Michael Hoffman wrote:
Paul McGuire wrote:
So "A" == 'a' is true in Python, not true in C.

I think you meant:
>>> "A" == "A"

True


Er, "A" == 'A'
--
Michael Hoffman
Jul 18 '05 #10

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

Similar topics

5
2228
by: Dave Brueck | last post by:
Is anybody else having problems sending email to python-list@python.org? About 48 hours ago or so my posts stopped making it to the list (I usually post via the mailing list rather than to the Usenet group). I tried unsubscribing and resubscribing to the list, but that turned out to be a mistake because once the list server sent me the email to confirm my subscription request, my reply email confirming it got ignored too!
3
1349
by: Brad Clements | last post by:
I have not seen any new posts in gmane.comp.python.general since 6/18/2004. However when I post to gmane, that post seems to make it out to the python list. Does anyone know if its a gmane problem, or a general news to python-list problem?
0
969
by: Armin Steinhoff | last post by:
Hi all, I ported ctypes 0.9.2 to QNX6.3 ... 99.9 % is working but only the unittest test_functions.py makes some problem. Here is the code: p = pointer(c_int(99)) result = f(p) self.failUnlessEqual(result.contents.value, 99) #---> works!!
0
6384
by: Brian van den Broek | last post by:
Hi all, There have been a few posts over the last month or so expressing a bit of exasperation with the "rising tide of newbie's". (Or, more accurately, the rising tide of questions from newbie's not trying to follow ESR's advice.) A month or so ago (in a thread found here: http://tinyurl.com/5bj8j), I suggested that it might help the situation if there were a python.org wiki page that amounted to a "Welcome to the Python community;...
41
3568
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of pairs, each pair indicates the sameness of the two indexes. Returns a partitioned list of same indexes.
39
3128
by: n00m | last post by:
Given a list of N arbitrarily permutated integers from set {1..N}. Need to find the ordering numbers of each integer in the LONGEST increasing sequence to which this number belongs. Sample: List: Corresponding ordering numbers:
7
3121
by: Brian | last post by:
First off, I am sorry for cluttering this group with my inept questions, but I am stuck again despite a few hours of hair pulling. I have a function (below) that takes a list of html pages that have images on them (not porn but boats). This function then (supposedly) goes through and extracts the links to those images and puts them into a list, appending with each iteration of the for loop. The list of html pages is 82 items long and...
409
11247
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are objects that are more than 4GB long. The problem is, when you have in thousands of places
2
162
by: Terry Reedy | last post by:
SUBHABRATA, I recommend you study this excellent response carefully. castironpi wrote: It starts with a concrete test case -- an 'executable problem statement'. To me, this is cleared and more useful than the 20 lines of prose you used. A single line English statement would be "Problem: Replace selected words in a text using a dictionary." Sometimes, less (words) really is more (understanding).
0
9879
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10981
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9477
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5716
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5907
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4521
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
2
4113
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3158
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.