473,789 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can anyone Pythonize this lexical algorithm?

I am writing a package manager and stuck unable to write the version
sorting function the algorithm is here http://www.linux.gr/cgi-bin/man/man2html?deb-version+5
and all other info is also in it please tell me how to do lexical
comparision in python it'll be cool if you just write the code!
Oct 9 '08 #1
2 1638
On Oct 9, 7:29*am, ShashiGowda <connect2sha... @gmail.comwrote :
I am writing a package manager and stuck unable to write the version
sorting function the algorithm is herehttp://www.linux.gr/cgi-bin/man/man2html?deb-version+5
and all other info is also in it please tell me how to do lexical
comparision in python it'll be cool if you just write the code!
On Oct 9, 7:29 am, ShashiGowda <connect2sha... @gmail.comwrote :
I am writing a package manager and stuck unable to write the version
sorting function the algorithm is herehttp://www.linux.gr/cgi-bin/man/man2html?deb-version+5
and all other info is also in it please tell me how to do lexical
comparision in python it'll be cool if you just write the code!
Step 1. Define a class, call it something like PackageVersion, with
an __init__ method that takes an string containing the version
string. In the body of __init__, use regular expressions, pyparsing,
str methods, whatever, to break up the version into the individual
fields.
Step 2. Implement a __cmp__ method on PackageVersion that performs
the desired version comparison logic.

Take a crack at writing some code, and come back with specific
questions. I doubt your hopes for coolness will be met.

-- Paul

Oct 9 '08 #2
ShashiGowda wrote:
I am writing a package manager and stuck unable to write the version
sorting function the algorithm is here http://www.linux.gr/cgi-bin/man/man2html?deb-version+5
and all other info is also in it please tell me how to do lexical
comparision in python it'll be cool if you just write the code!
Assuming you want 10.1 to sort after 9.8 and 1.10 after 1.9, you want to
compare tuples or lists of ints.

Oct 9 '08 #3

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

Similar topics

0
1462
by: Collin VanDyck | last post by:
Hello! I have set up a pluggable SAX transformation pipeline which is made up of individual nodes that transform the source XML, and for the most part it works well. Each node in the pipeline is assigned a ContentHandler and a LexicalHandler by the transformation framework. Each node in the pipeline may either be: * a class that implements ContentHandler and LexicalHandler
4
4401
by: bariole | last post by:
Hi I am trying to make lexical analysis of some simplified html code with flex tool. However that kind of work is new to me and I don't know where to start. I have searched a web but I didn't find anything useful. I found tools like LEXHTML.CXX library but I have no need for that. What I need is simple overview of working ideas of most usual html lexical analysators like ones inside IE or Gecko. Something like good
13
1952
by: Lucas Zimmerman | last post by:
Is there any Lex code available that describes how to scan C programs? I'd like to read someting related to this. One of my doubs is how C deals with ambiguities, for example, `a = x/*p;' or `a = x//*...*/-3;' (considering c99's `//'). thanks in advance, n.
18
1801
by: jslowery | last post by:
I am not completely knowledgable about the status of lexical scoping in Python, but it was my understanding that this was added in a long time ago around python2.1-python2.2 I am using python2.4 and the following code throws a "status variable" not found in the inner-most function, even when I try to "global" it. def collect(fields, reducer): def rule(record): status = True
2
2330
by: Frank-René Schäfer | last post by:
penSource Project 'Quex': http://quex.sf.net Last weekend, the lexical analyser generator 'Quex' has been released on SourceForge. Quex provides advanced features for mode definitions and event handling. Among its features are -- Creation of a complete C++ environment for lexical analyser engines. -- Modes management:
6
2046
by: enaeher | last post by:
I would expect this code: globalFnArray = ; for (var i = 0; i < 5; i++) { globalFnArray.push (function () { alert (i) }); } for (var j = 0; j < 5; j++) { globalFnArray(); } to alert 0, 1, 2, 3, and 4. Instead, I get 5, 5, 5, 5, and 5 in Firefox, indicating that all of
14
2184
by: Khookie | last post by:
Woah... is it just me or do C programmers don't bother talking about how cool C can be (compared to Lisp, Haskell, etc.) - functionally speaking? // Lexical scoping - via nested functions #include <stdio.h> int main() { int x = 10;
2
1468
by: moon123 | last post by:
We have to program it in two parts: the lexical analyzer and the syntax analyzer plus semantic.The lexical analyzer should recognize the token using DFA and return the token and the value. The syntax and semantic part can be done by using any algorithm that can check for the correct syntax.You can select one programming language as the source language to build compiler to it or construct your own ones or take the one I write it in the appendix...
3
8796
by: globalrev | last post by:
i cant figure outif python has lexical or general scope. it seems functions have lexical scope but with some restrictions and some non-function scopes are dynamic?
0
9663
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
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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
10195
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9016
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...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4090
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
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.